Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pandas import read_csv
- from sklearn.neighbors import KNeighborsClassifier
- import matplotlib.pyplot as plt
- from mpl_toolkits.mplot3d import Axes3D
- from sklearn import preprocessing
- from matplotlib import style
- import sklearn
- import numpy as np
- style.use('bmh')
- DATA = read_csv('Iris_Classifier.csv')
- X = np.array(DATA[['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']])
- Y = np.array(DATA['Species'])
- X_Train, X_Test, Y_Train, Y_Test = sklearn.model_selection.train_test_split(X, Y, test_size=0.1)
- KNN_Model = KNeighborsClassifier(n_neighbors=5)
- KNN_Model.fit(X_Train, Y_Train)
- Accuracity = KNN_Model.score(X_Test, Y_Test)
- print('Accuracity:', str(Accuracity*100)[:5] + str('%'))
- Prediction = KNN_Model.predict([[5.1, 3.5, 1.4, 0.2]])[0]
- print(Prediction)
- labelEncoder = preprocessing.LabelEncoder()
- numericSpecies = labelEncoder.fit_transform(DATA['Species'])
- ax = plt.axes(projection='3d')
- for i in range(len(DATA)):
- ax.scatter3D(DATA['SepalLengthCm'][i], DATA['SepalWidthCm'][i], numericSpecies[i], color=('red', 'green', 'blue')[numericSpecies[i]], alpha=1, edgecolors='black')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement