|
a |
|
b/BEPROJECTWEBSITE/2nd_model_decision_tree.py |
|
|
1 |
# -*- coding: utf-8 -*- |
|
|
2 |
"""2nd Model - Decision_Tree.ipynb |
|
|
3 |
|
|
|
4 |
Automatically generated by Colaboratory. |
|
|
5 |
|
|
|
6 |
Original file is located at |
|
|
7 |
https://colab.research.google.com/drive/1Tv8RApC_NwpNr9HDNUsyufsbETl0nZyc |
|
|
8 |
""" |
|
|
9 |
|
|
|
10 |
import pandas as pd |
|
|
11 |
import pickle |
|
|
12 |
|
|
|
13 |
df = pd.read_csv('Upscale - Sheet3.csv') |
|
|
14 |
|
|
|
15 |
df = df.drop(columns="Hybridization REF") |
|
|
16 |
from sklearn.model_selection import train_test_split |
|
|
17 |
training_set, test_set = train_test_split(df, test_size = 0.3, random_state = 1) |
|
|
18 |
|
|
|
19 |
X_train = training_set.iloc[:,0:3].values |
|
|
20 |
Y_train = training_set.iloc[:,3].values |
|
|
21 |
|
|
|
22 |
X_test = test_set.iloc[:,0:3].values |
|
|
23 |
Y_test = test_set.iloc[:,3].values |
|
|
24 |
|
|
|
25 |
from sklearn.tree import DecisionTreeClassifier |
|
|
26 |
dtree = DecisionTreeClassifier(max_depth = 10, random_state = 101, max_features = None, min_samples_leaf = 15) |
|
|
27 |
dtree.fit(X_train, Y_train) |
|
|
28 |
|
|
|
29 |
y_pred = dtree.predict(X_test) |
|
|
30 |
|
|
|
31 |
from sklearn.metrics import accuracy_score |
|
|
32 |
accuracy_score(Y_test,y_pred) |
|
|
33 |
|
|
|
34 |
from sklearn.metrics import precision_score, recall_score, f1_score |
|
|
35 |
precision = precision_score(Y_test,y_pred) |
|
|
36 |
print(precision) |
|
|
37 |
|
|
|
38 |
recall_score(Y_test, y_pred) |
|
|
39 |
|
|
|
40 |
f1_score(Y_test, y_pred) |
|
|
41 |
|
|
|
42 |
#serialization and de-serialization |
|
|
43 |
pickle.dump(dtree, open('model.pkl','wb')) |
|
|
44 |
|
|
|
45 |
model = pickle.load(open('model.pkl', 'rb')) |