Project

K-Nearest Neighbor

from math import gamma
from typing import Type
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
iris=load_iris()
print(dir(iris))
print(type(iris))
df=pd.DataFrame(iris.data,columns=iris.feature_names)
print(df)
df['target']=iris.target
print(df)
print(df.describe())
print(df[df.target==1])
print(iris.target_names)
from sklearn.model_selection import train_test_split
X=df[["sepal length (cm)","sepal width (cm)","petal length (cm)","petal width (cm)"]]
Y=df.target
print(X)
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.3,random_state=4)
print(len(X_test))
print(len(X_train))

from sklearn.neighbors import KNeighborsClassifier
knn=KNeighborsClassifier(n_neighbors=3)

print(knn.fit(X_train,Y_train))
print("KNN Accuracy = ",knn.score(X_test,Y_test))
print("KNN X Test Data PREDICTION:",knn.predict(X_test))
print("KNN Y Test Data: ",Y_test) 
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.