commit_natalia2
@ -1,100 +1,121 @@
|
|||||||
20,0,2,4,3,2
|
14,1,3,14,1,2
|
||||||
57,0,8,2,1,2
|
7,1,1,11,2,1
|
||||||
50,1,3,4,1,1
|
18,1,3,15,1,1
|
||||||
51,1,6,1,1,1
|
8,0,2,11,2,3
|
||||||
82,1,9,1,2,2
|
11,0,4,12,1,3
|
||||||
73,1,5,4,3,2
|
20,0,4,12,1,2
|
||||||
65,0,7,3,2,1
|
9,1,1,11,1,2
|
||||||
16,1,9,2,3,1
|
7,1,2,15,0,1
|
||||||
23,0,1,4,3,1
|
20,1,7,16,1,2
|
||||||
74,0,10,3,1,1
|
13,1,2,15,5,4
|
||||||
85,1,5,4,1,2
|
39,0,10,11,3,4
|
||||||
35,0,2,1,2,1
|
29,1,3,6,5,4
|
||||||
79,1,9,4,1,2
|
44,1,7,5,5,4
|
||||||
56,0,7,2,1,2
|
65,1,5,4,5,4
|
||||||
51,0,6,4,3,2
|
47,1,5,5,5,4
|
||||||
13,1,8,1,3,1
|
78,1,0,2,5,4
|
||||||
30,0,8,2,2,2
|
73,1,1,4,5,4
|
||||||
50,0,5,5,1,2
|
63,1,5,4,5,4
|
||||||
39,1,9,3,3,1
|
26,1,9,9,5,4
|
||||||
20,0,7,5,3,1
|
38,1,8,5,4,4
|
||||||
63,1,8,4,1,1
|
20,1,8,4,4,4
|
||||||
74,1,2,1,3,1
|
45,1,8,4,5,4
|
||||||
46,1,7,3,1,2
|
50,1,8,6,4,4
|
||||||
52,0,5,3,3,1
|
45,1,9,6,5,4
|
||||||
39,0,9,1,3,1
|
35,1,8,8,5,4
|
||||||
14,1,4,1,3,2
|
29,1,3,6,5,5
|
||||||
81,1,2,1,3,1
|
29,0,9,9,5,5
|
||||||
79,0,10,4,1,2
|
15,0,5,4,4,5
|
||||||
69,0,1,5,1,2
|
20,0,4,4,5,5
|
||||||
87,1,3,4,3,2
|
25,0,4,4,4,5
|
||||||
72,1,9,1,3,1
|
30,0,6,4,4,5
|
||||||
85,0,5,4,1,2
|
35,0,7,6,4,5
|
||||||
59,1,10,5,3,1
|
45,0,6,5,4,5
|
||||||
32,1,8,1,3,1
|
44,1,7,5,4,6
|
||||||
28,0,3,1,1,2
|
44,1,7,5,3,6
|
||||||
77,0,10,3,1,1
|
30,0,7,5,3,6
|
||||||
82,1,4,5,3,2
|
10,1,6,5,3,6
|
||||||
30,0,9,1,3,2
|
15,1,7,5,3,6
|
||||||
83,1,9,2,3,2
|
17,0,5,5,3,6
|
||||||
88,1,2,3,2,1
|
25,1,6,4,4,6
|
||||||
72,1,8,3,2,1
|
46,1,6,3,4,6
|
||||||
87,1,9,2,2,2
|
65,1,5,4,0,7
|
||||||
13,0,8,5,2,1
|
10,0,5,4,1,7
|
||||||
47,0,6,3,1,2
|
15,0,5,4,0,7
|
||||||
51,1,1,4,3,1
|
16,1,5,4,0,7
|
||||||
27,0,4,5,2,2
|
17,1,5,4,1,7
|
||||||
50,1,7,5,1,2
|
16,0,5,4,0,7
|
||||||
16,1,2,4,2,2
|
20,0,5,4,1,7
|
||||||
29,0,8,4,3,2
|
21,0,5,4,0,7
|
||||||
80,1,2,3,2,1
|
25,1,5,4,0,7
|
||||||
16,0,10,2,1,1
|
27,1,5,4,0,7
|
||||||
76,0,4,4,3,2
|
28,1,5,4,1,7
|
||||||
44,1,6,1,1,2
|
29,1,5,4,1,7
|
||||||
63,0,5,2,2,2
|
29,1,5,4,0,7
|
||||||
12,1,5,4,3,2
|
29,0,5,4,0,7
|
||||||
73,1,1,5,1,2
|
30,0,5,4,0,7
|
||||||
39,1,7,3,3,1
|
31,1,5,4,0,7
|
||||||
10,0,8,3,1,2
|
32,1,6,3,0,7
|
||||||
32,0,7,4,3,1
|
34,1,6,4,0,7
|
||||||
32,0,8,1,2,1
|
35,1,6,4,1,7
|
||||||
74,1,2,4,1,2
|
46,1,5,4,1,7
|
||||||
77,1,9,1,3,1
|
47,1,5,4,1,7
|
||||||
13,1,2,1,1,1
|
47,0,5,4,1,7
|
||||||
61,0,10,1,1,2
|
47,0,5,4,0,7
|
||||||
48,1,2,1,1,1
|
48,1,5,4,1,7
|
||||||
11,0,4,5,3,1
|
48,1,5,4,0,7
|
||||||
80,0,10,3,3,1
|
48,0,5,4,1,7
|
||||||
33,0,9,5,3,2
|
49,1,5,4,1,7
|
||||||
53,1,5,2,3,2
|
49,0,5,4,1,7
|
||||||
56,0,10,2,2,2
|
7,0,3,10,0,1
|
||||||
25,1,4,4,1,2
|
8,0,3,10,0,1
|
||||||
27,0,8,3,3,2
|
10,1,4,10,0,1
|
||||||
83,0,1,1,1,2
|
10,0,2,9,0,1
|
||||||
49,0,4,3,2,2
|
9,1,3,9,0,1
|
||||||
76,0,10,3,1,1
|
13,1,3,10,0,1
|
||||||
40,0,1,5,2,2
|
13,1,4,9,0,1
|
||||||
73,1,3,4,2,1
|
15,0,2,8,0,1
|
||||||
19,1,2,4,2,2
|
14,1,2,8,0,1
|
||||||
77,1,7,2,3,1
|
16,1,3,8,0,1
|
||||||
52,0,5,4,3,2
|
16,1,3,9,1,1
|
||||||
29,0,10,2,3,1
|
16,0,3,9,1,1
|
||||||
28,1,5,1,3,2
|
16,0,4,8,1,1
|
||||||
63,0,1,5,3,2
|
16,1,4,10,1,1
|
||||||
84,1,4,2,1,2
|
30,0,4,8,0,1
|
||||||
31,0,9,1,3,1
|
30,1,4,8,0,1
|
||||||
46,1,3,5,1,1
|
30,1,5,9,1,1
|
||||||
84,0,6,5,3,1
|
30,0,3,10,1,1
|
||||||
30,0,7,1,2,2
|
31,0,3,9,0,1
|
||||||
29,1,7,1,1,1
|
31,0,4,9,1,1
|
||||||
46,1,5,3,3,2
|
31,1,3,10,0,1
|
||||||
17,1,8,1,1,1
|
17,0,15,7,2,2
|
||||||
37,0,10,4,2,1
|
17,0,14,7,2,2
|
||||||
43,0,6,1,3,1
|
17,0,14,10,1,2
|
||||||
57,1,6,1,2,2
|
17,0,13,10,1,2
|
||||||
58,1,4,1,3,2
|
17,1,14,10,2,2
|
||||||
59,0,1,4,3,1
|
17,1,15,7,1,2
|
||||||
26,0,7,2,3,2
|
18,0,13,7,2,2
|
||||||
43,0,2,1,3,1
|
18,0,15,7,1,2
|
||||||
66,0,8,2,1,1
|
18,1,13,7,1,2
|
||||||
85,1,2,1,2,2
|
20,0,14,8,3,2
|
||||||
|
20,1,13,7,3,2
|
||||||
|
21,1,15,5,1,2
|
||||||
|
21,0,13,6,2,2
|
||||||
|
30,0,13,6,2,2
|
||||||
|
30,0,15,5,1,2
|
||||||
|
30,0,14,6,1,2
|
||||||
|
31,0,15,5,1,2
|
||||||
|
31,1,15,4,2,2
|
||||||
|
31,1,14,6,2,2
|
||||||
|
31,1,14,5,0,2
|
||||||
|
20,1,10,3,0,3
|
||||||
|
20,1,9,4,0,3
|
||||||
|
21,1,10,3,0,3
|
||||||
|
21,0,9,4,0,3
|
||||||
|
21,0,10,5,0,3
|
||||||
|
30,0,10,5,0,3
|
||||||
|
40,0,10,5,0,3
|
||||||
|
50,0,10,5,0,3
|
||||||
|
65,0,10,5,0,3
|
||||||
|
21,0,11,4,5,4
|
||||||
|
22,1,11,4,5,4
|
||||||
|
|
@ -1,54 +0,0 @@
|
|||||||
# Load libraries
|
|
||||||
import pandas as pd
|
|
||||||
from sklearn.tree import DecisionTreeClassifier # Import Decision Tree Classifier
|
|
||||||
from sklearn.model_selection import train_test_split # Import train_test_split function
|
|
||||||
from sklearn import metrics #Import scikit-learn metrics module for accuracy calculation
|
|
||||||
from sklearn.tree import export_graphviz
|
|
||||||
from sklearn.externals.six import StringIO
|
|
||||||
from IPython.display import Image
|
|
||||||
import pydotplus
|
|
||||||
|
|
||||||
col_names = ['age', 'sex', 'fat', 'spicy', 'hungry', 'budget']
|
|
||||||
# load dataset
|
|
||||||
pima = pd.read_csv("nazwa.csv", header=None, names=col_names)
|
|
||||||
|
|
||||||
#split dataset in features and target variable
|
|
||||||
feature_cols = ['age', 'sex', 'fat', 'spicy']
|
|
||||||
X = pima[feature_cols] # Features
|
|
||||||
y = pima.label # Target variable
|
|
||||||
|
|
||||||
# Split dataset into training set and test set
|
|
||||||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1) # 70% training and 30% test
|
|
||||||
|
|
||||||
# Create Decision Tree classifer object
|
|
||||||
clf = DecisionTreeClassifier()
|
|
||||||
|
|
||||||
# Train Decision Tree Classifer
|
|
||||||
clf = clf.fit(X_train,y_train)
|
|
||||||
|
|
||||||
#Predict the response for test dataset
|
|
||||||
y_pred = clf.predict(X_test)
|
|
||||||
|
|
||||||
# Model Accuracy, how often is the classifier correct?
|
|
||||||
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
|
|
||||||
|
|
||||||
dot_data = StringIO()
|
|
||||||
export_graphviz(clf, out_file=dot_data,
|
|
||||||
filled=True, rounded=True,
|
|
||||||
special_characters=True,feature_names = feature_cols,class_names=['0','1'])
|
|
||||||
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
|
|
||||||
graph.write_png('food_tree.png')
|
|
||||||
Image(graph.create_png())
|
|
||||||
|
|
||||||
|
|
||||||
# Create Decision Tree classifer object
|
|
||||||
clf = DecisionTreeClassifier(criterion="entropy", max_depth=3)
|
|
||||||
|
|
||||||
# Train Decision Tree Classifer
|
|
||||||
clf = clf.fit(X_train,y_train)
|
|
||||||
|
|
||||||
#Predict the response for test dataset
|
|
||||||
y_pred = clf.predict(X_test)
|
|
||||||
|
|
||||||
# Model Accuracy, how often is the classifier correct?
|
|
||||||
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
|
|
@ -0,0 +1,87 @@
|
|||||||
|
import pandas as pd
|
||||||
|
try:
|
||||||
|
from StringIO import StringIO
|
||||||
|
except ImportError:
|
||||||
|
from io import StringIO
|
||||||
|
from io import StringIO
|
||||||
|
from sklearn.tree import DecisionTreeClassifier
|
||||||
|
from sklearn.model_selection import train_test_split
|
||||||
|
from sklearn import metrics
|
||||||
|
from sklearn.tree import export_graphviz
|
||||||
|
import joblib
|
||||||
|
from IPython.display import Image
|
||||||
|
import pydotplus
|
||||||
|
import os
|
||||||
|
os.environ["PATH"] += os.pathsep + r'C:\Program Files (x86)\Graphviz2.38\bin'
|
||||||
|
|
||||||
|
def main():
|
||||||
|
dot_data = StringIO()
|
||||||
|
col_names = ['age', 'sex', 'fat', 'fiber', 'spicy', 'number']
|
||||||
|
#import danych
|
||||||
|
model_tree = pd.read_csv("Nowy.csv", header=None, names=col_names)
|
||||||
|
model_tree.head()
|
||||||
|
#seperacja danych cechy
|
||||||
|
feature_cols = ['age', 'sex', 'fat', 'fiber', 'spicy']
|
||||||
|
X = model_tree[feature_cols]
|
||||||
|
#separacja danych etykieta
|
||||||
|
y = model_tree.number
|
||||||
|
# Target variable
|
||||||
|
|
||||||
|
#podział danych na zestaw treningowy i testowy; 70% trening 30% test
|
||||||
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
|
||||||
|
random_state=1) # 70% training and 30% test
|
||||||
|
|
||||||
|
###############################
|
||||||
|
# stworzenie -obiektu- drzewa Decision Tree classifer
|
||||||
|
clf = DecisionTreeClassifier()
|
||||||
|
|
||||||
|
# drzewo treningowe
|
||||||
|
clf = clf.fit(X_train, y_train)
|
||||||
|
|
||||||
|
#generowanie wyników dla zbioru testowego
|
||||||
|
y_pred = clf.predict(X_test)
|
||||||
|
#print(y_pred)
|
||||||
|
|
||||||
|
#Akuratność dla modelu danych
|
||||||
|
print("Accuracy:", metrics.accuracy_score(y_test, y_pred))
|
||||||
|
|
||||||
|
dot_data = StringIO()
|
||||||
|
#tworzenie graficznego drzewa
|
||||||
|
export_graphviz(clf, out_file=dot_data,
|
||||||
|
filled=True, rounded=True,
|
||||||
|
special_characters=True, feature_names=feature_cols,
|
||||||
|
class_names=['1', '2', '3', '4', '5', '6', '7'])
|
||||||
|
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
|
||||||
|
graph.write_png('polecanie_1.png')
|
||||||
|
Image(graph.create_png())
|
||||||
|
|
||||||
|
# ************************************************************
|
||||||
|
# stworzenie -obiektu- drzewa Decision Tree classifer z kryterium entropii
|
||||||
|
clf = DecisionTreeClassifier(criterion="entropy")
|
||||||
|
|
||||||
|
#drzewo testowe-z entripią
|
||||||
|
clf = clf.fit(X_train, y_train)
|
||||||
|
|
||||||
|
#generowanie wyników dla zbioru testowego
|
||||||
|
y_pred = clf.predict(X_test)
|
||||||
|
|
||||||
|
#Akuratność dla modelu danych z warunkiem entropii
|
||||||
|
print("Accuracy:", metrics.accuracy_score(y_test, y_pred))
|
||||||
|
|
||||||
|
#stowrzenie graficznego drzewa z warunkiem entropii
|
||||||
|
dot_data = StringIO()
|
||||||
|
export_graphviz(clf, out_file=dot_data,
|
||||||
|
filled=True, rounded=True,
|
||||||
|
special_characters=True, feature_names=feature_cols,
|
||||||
|
class_names=['1', '2', '3', '4', '5', '6', '7'])
|
||||||
|
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
|
||||||
|
graph.write_png('polecanie_2_entropia.png')
|
||||||
|
Image(graph.create_png())
|
||||||
|
|
||||||
|
#zapisanie modelu danych do pliku
|
||||||
|
file_name = 'final_model.sav'
|
||||||
|
joblib.dump(clf, file_name)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
main()
|
BIN
Restaurant/Natalia/danie1.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
Restaurant/Natalia/danie2.png
Normal file
After Width: | Height: | Size: 1.2 MiB |
BIN
Restaurant/Natalia/danie3.png
Normal file
After Width: | Height: | Size: 167 KiB |
BIN
Restaurant/Natalia/danie4.png
Normal file
After Width: | Height: | Size: 2.8 MiB |
BIN
Restaurant/Natalia/danie5.png
Normal file
After Width: | Height: | Size: 64 KiB |
BIN
Restaurant/Natalia/danie6.png
Normal file
After Width: | Height: | Size: 106 KiB |
BIN
Restaurant/Natalia/danie7.png
Normal file
After Width: | Height: | Size: 175 KiB |
BIN
Restaurant/Natalia/digest_entropy.png
Normal file
After Width: | Height: | Size: 87 KiB |
BIN
Restaurant/Natalia/final_model.sav
Normal file
BIN
Restaurant/Natalia/finalized_model.sav
Normal file
BIN
Restaurant/Natalia/model.sav
Normal file
BIN
Restaurant/Natalia/polecanie_1.png
Normal file
After Width: | Height: | Size: 275 KiB |
BIN
Restaurant/Natalia/polecanie_2_entropia.png
Normal file
After Width: | Height: | Size: 274 KiB |