-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_pipeline.py
More file actions
30 lines (23 loc) · 772 Bytes
/
4_pipeline.py
File metadata and controls
30 lines (23 loc) · 772 Bytes
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
30
from sklearn import datasets
iris = datasets.load_iris()
#Metadata of the dataset
x = iris.data
y = iris.target
#Example 1 of the dataset
#print iris.data[0]
#print iris.target[0]
#prepare train and test data
from sklearn.cross_validation import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x,y, test_size=.5)
#Classifier-1
from sklearn import tree
my_classifier = tree.DecisionTreeClassifier()
#Classifier-2
from sklearn.neighbors import KNeighborsClassifier
my_classifier = KNeighborsClassifier()
#Training Classifier, Prediction and Accuracy Calculation
my_classifier.fit(x_train, y_train)
predictions = my_classifier.predict(x_test)
#print predictions
from sklearn.metrics import accuracy_score
print accuracy_score(y_test,predictions)