forked from raunaks42/StarQuasarClassifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknnvis.py
More file actions
18 lines (16 loc) · 681 Bytes
/
knnvis.py
File metadata and controls
18 lines (16 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import matplotlib.pyplot as plt
import pandas as pd
from sklearn import datasets, neighbors
from mlxtend.plotting import plot_decision_regions
def knn_comparison(data, k):
x = data[['principal component 1','principal component 2']].values
y = data['class'].astype(int).values
clf = neighbors.KNeighborsClassifier(n_neighbors=k)
clf.fit(x, y)# Plotting decision region
plot_decision_regions(x, y, clf=clf, legend=2)# Adding axes annotations
plt.xlabel('Principal Component 1')
plt.ylabel('Principal Component 2')
plt.title('Knn with K='+ str(k))
plt.savefig('knnvis'+repr(k)+'.png')
data1 = pd.read_csv('pca_cat1.csv')
knn_comparison(data1, 25)