text_plain_output_1.png
from sklearn.metrics import accuracy_score

from sklearn.model_selection import train_test_split

from sklearn.neighbors import KNeighborsClassifier

import numpy as np

import pandas as pd

d = pd.read_excel('/kaggle/input/rice-dataset-commeo-and-osmancik/Rice_Dataset_Commeo_and_Osmancik/Rice_Cammeo_Osmancik.xlsx')
d

from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score
x_train = d[['Area', 'Perimeter', 'Major_Axis_Length', 'Minor_Axis_Length', 'Eccentricity', 'Convex_Area', 'Extent']]
y_train = d['Class']
k = 3
knn = KNeighborsClassifier(n_neighbors=k)
knn.fit(x_train, y_train)
x_test = np.array([[1.2, 1.0, 2.8, 1.2, 1.0, 2.8, 1.2]])
target = knn.predict(x_test)

from sklearn.model_selection import train_test_split
x_train, x_holdout, y_train, y_holdout = train_test_split(d[['Area', 'Perimeter', 'Major_Axis_Length', 'Minor_Axis_Length', 'Eccentricity', 'Convex_Area', 'Extent']], d['Class'], test_size=0.3, random_state=17)
n_list = list(range(1, 50))
acclist = []
for n in n_list:
    knn = KNeighborsClassifier(n_neighbors=n)
    knn.fit(x_train, y_train)
    knn_pred = knn.predict(x_holdout)
    accur = accuracy_score(y_holdout, knn_pred)
    print('accuracy: ', accur)
    acclist.append(accur)