forked from officialgupta/MachineLearningRecipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.py
29 lines (18 loc) · 769 Bytes
/
pipeline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from sklearn import datasets
from sklearn.model_selection import train_test_split
# from sklearn import tree # replaced with Kneighbors
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score
# COLLECT TRAINING DATA
iris = datasets.load_iris()
X = iris.data #input FEATURES
y = iris.target #output LABELS
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size= .5) #splits the data so some can be used for testing 50%
# TRAIN CLASSIFIER
# my_classifier = tree.DecisionTreeClassifier() #replaced with Kneighbor
my_classifier = KNeighborsClassifier()
my_classifier.fit(X_train, y_train)
# MAKE PREDICTIONS
predictions = my_classifier.predict(X_test)
# CHECK ACCURACY
print(accuracy_score(y_test, predictions))