You can access the detailed description of the project from this link https://www.kaggle.com/code/erdemtaha/prediction-cancer-data-with-k-nn-95
Using the Knn algorithm, we analyze and classify the cancer cells we have as benign or malignant
1 = M (Malignant Cancer Cell)
0 = B (Benign Cancer Cell)
My data consists of 569 cancer cells and 30 characteristics of each cell.
from sklearn.neighbors import KNeighborsClassifier Score_list = [] for each in range(1,15): knn2 = KNeighborsClassifier(n_neighbors = each) knn2.fit(x_train,y_train) Score_list.append(knn2.score(x_test,y_test)) plt.plot(range(1,15),Score_list) plt.xlabel("k values") plt.ylabel("accuracy") plt.show()Here we examine the accuracy score of the K-nn Model and we get a score of 0.953216373742690059 which indicates that we have trained a good model in general, of course, better results can be obtained by playing with the values.
from sklearn.neighbors import KNeighborsClassifier knn = KNeighborsClassifier(n_neighbors=3) knn.fit(x_train,y_train) prediction = knn.predict(x_test) print("{} nn {} score".format(3,knn.score(x_test,y_test)))🏆 Test accuracy: 95.32% (3 nn)
