commit_natalia2

This commit is contained in:
Natalia 2020-05-24 18:02:53 +02:00
parent 895d554dce
commit 260ce4fe62
16 changed files with 208 additions and 154 deletions

View File

@ -1,100 +1,121 @@
20,0,2,4,3,2
57,0,8,2,1,2
50,1,3,4,1,1
51,1,6,1,1,1
82,1,9,1,2,2
73,1,5,4,3,2
65,0,7,3,2,1
16,1,9,2,3,1
23,0,1,4,3,1
74,0,10,3,1,1
85,1,5,4,1,2
35,0,2,1,2,1
79,1,9,4,1,2
56,0,7,2,1,2
51,0,6,4,3,2
13,1,8,1,3,1
30,0,8,2,2,2
50,0,5,5,1,2
39,1,9,3,3,1
20,0,7,5,3,1
63,1,8,4,1,1
74,1,2,1,3,1
46,1,7,3,1,2
52,0,5,3,3,1
39,0,9,1,3,1
14,1,4,1,3,2
81,1,2,1,3,1
79,0,10,4,1,2
69,0,1,5,1,2
87,1,3,4,3,2
72,1,9,1,3,1
85,0,5,4,1,2
59,1,10,5,3,1
32,1,8,1,3,1
28,0,3,1,1,2
77,0,10,3,1,1
82,1,4,5,3,2
30,0,9,1,3,2
83,1,9,2,3,2
88,1,2,3,2,1
72,1,8,3,2,1
87,1,9,2,2,2
13,0,8,5,2,1
47,0,6,3,1,2
51,1,1,4,3,1
27,0,4,5,2,2
50,1,7,5,1,2
16,1,2,4,2,2
29,0,8,4,3,2
80,1,2,3,2,1
16,0,10,2,1,1
76,0,4,4,3,2
44,1,6,1,1,2
63,0,5,2,2,2
12,1,5,4,3,2
73,1,1,5,1,2
39,1,7,3,3,1
10,0,8,3,1,2
32,0,7,4,3,1
32,0,8,1,2,1
74,1,2,4,1,2
77,1,9,1,3,1
13,1,2,1,1,1
61,0,10,1,1,2
48,1,2,1,1,1
11,0,4,5,3,1
80,0,10,3,3,1
33,0,9,5,3,2
53,1,5,2,3,2
56,0,10,2,2,2
25,1,4,4,1,2
27,0,8,3,3,2
83,0,1,1,1,2
49,0,4,3,2,2
76,0,10,3,1,1
40,0,1,5,2,2
73,1,3,4,2,1
19,1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,1,7
47,0,5,4,0,7
48,1,5,4,1,7
48,1,5,4,0,7
48,0,5,4,1,7
49,1,5,4,1,7
49,0,5,4,1,7
7,0,3,10,0,1
8,0,3,10,0,1
10,1,4,10,0,1
10,0,2,9,0,1
9,1,3,9,0,1
13,1,3,10,0,1
13,1,4,9,0,1
15,0,2,8,0,1
14,1,2,8,0,1
16,1,3,8,0,1
16,1,3,9,1,1
16,0,3,9,1,1
16,0,4,8,1,1
16,1,4,10,1,1
30,0,4,8,0,1
30,1,4,8,0,1
30,1,5,9,1,1
30,0,3,10,1,1
31,0,3,9,0,1
31,0,4,9,1,1
31,1,3,10,0,1
17,0,15,7,2,2
17,0,14,7,2,2
17,0,14,10,1,2
17,0,13,10,1,2
17,1,14,10,2,2
17,1,15,7,1,2
18,0,13,7,2,2
18,0,15,7,1,2
18,1,13,7,1,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 20 14 0 1 3 4 14 1 2 2
2 57 7 0 1 1 2 11 2 2 8 1
3 50 18 1 1 1 3 4 15 1 1 3 1
4 51 8 1 0 1 2 1 11 2 1 6 3
5 82 11 1 0 2 4 1 12 1 2 9 3
6 73 20 1 0 3 4 4 12 1 2 5 2
7 65 9 0 1 2 1 3 11 1 1 7 2
8 16 7 1 1 3 2 2 15 0 1 9 1
9 23 20 0 1 3 7 4 16 1 1 1 2
10 74 13 0 1 1 2 3 15 5 1 10 4
11 85 39 1 0 1 10 4 11 3 2 5 4
12 35 29 0 1 2 3 1 6 5 1 2 4
13 79 44 1 1 1 7 4 5 5 2 9 4
14 56 65 0 1 1 5 2 4 5 2 7 4
15 51 47 0 1 3 5 4 5 5 2 6 4
16 13 78 1 1 3 0 1 2 5 1 8 4
17 30 73 0 1 2 1 2 4 5 2 8 4
18 50 63 0 1 1 5 5 4 5 2 5 4
19 39 26 1 1 3 9 3 9 5 1 9 4
20 20 38 0 1 3 8 5 5 4 1 7 4
21 63 20 1 1 1 8 4 4 4 1 8 4
22 74 45 1 1 3 8 1 4 5 1 2 4
23 46 50 1 1 1 8 3 6 4 2 7 4
24 52 45 0 1 3 9 3 6 5 1 5 4
25 39 35 0 1 3 8 1 8 5 1 9 4
26 14 29 1 1 3 1 6 5 2 4 5
27 81 29 1 0 3 9 1 9 5 1 2 5
28 79 15 0 0 1 5 4 4 4 2 10 5
29 69 20 0 0 1 4 5 4 5 2 1 5
30 87 25 1 0 3 4 4 4 4 2 3 5
31 72 30 1 0 3 6 1 4 4 1 9 5
32 85 35 0 0 1 7 4 6 4 2 5
33 59 45 1 0 3 6 5 5 4 1 10 5
34 32 44 1 1 3 7 1 5 4 1 8 6
35 28 44 0 1 1 7 1 5 3 2 3 6
36 77 30 0 0 1 7 3 5 3 1 10 6
37 82 10 1 1 3 6 5 5 3 2 4 6
38 30 15 0 1 3 7 1 5 3 2 9 6
39 83 17 1 0 3 5 2 5 3 2 9 6
40 88 25 1 1 2 6 3 4 4 1 2 6
41 72 46 1 1 2 6 3 3 4 1 8 6
42 87 65 1 1 2 5 2 4 0 2 9 7
43 13 10 0 0 2 5 5 4 1 1 8 7
44 47 15 0 0 1 5 3 4 0 2 6 7
45 51 16 1 1 3 5 4 4 0 1 1 7
46 27 17 0 1 2 5 5 4 1 2 4 7
47 50 16 1 0 1 5 5 4 0 2 7
48 16 20 1 0 2 5 4 4 1 2 2 7
49 29 21 0 0 3 5 4 4 0 2 8 7
50 80 25 1 1 2 5 3 4 0 1 2 7
51 16 27 0 1 1 5 2 4 0 1 10 7
52 76 28 0 1 3 5 4 4 1 2 4 7
53 44 29 1 1 1 5 1 4 1 2 6 7
54 63 29 0 1 2 5 2 4 0 2 5 7
55 12 29 1 0 3 5 4 4 0 2 5 7
56 73 30 1 0 1 5 5 4 0 2 1 7
57 39 31 1 1 3 5 3 4 0 1 7
58 10 32 0 1 1 6 3 3 0 2 8 7
59 32 34 0 1 3 6 4 4 0 1 7
60 32 35 0 1 2 6 1 4 1 1 8 7
61 74 46 1 1 1 5 4 4 1 2 2 7
62 77 47 1 1 3 5 1 4 1 1 9 7
63 13 47 1 0 1 5 1 4 1 1 2 7
64 61 47 0 0 1 5 1 4 0 2 10 7
65 48 48 1 1 1 5 1 4 1 1 2 7
66 11 48 0 1 3 5 5 4 0 1 4 7
67 80 48 0 0 3 5 3 4 1 1 10 7
68 33 49 0 1 3 5 5 4 1 2 9 7
69 53 49 1 0 3 5 2 4 1 2 5 7
70 56 7 0 0 2 3 2 10 0 2 10 1
71 25 8 1 0 1 3 4 10 0 2 4 1
72 27 10 0 1 3 4 3 10 0 2 8 1
73 83 10 0 0 1 2 1 9 0 2 1
74 49 9 0 1 2 3 3 9 0 2 4 1
75 76 13 0 1 1 3 3 10 0 1 10 1
76 40 13 0 1 2 4 5 9 0 2 1
77 73 15 1 0 2 4 8 0 1 3 1
78 19 14 1 1 2 4 8 0 2 2 1
79 77 16 1 1 3 2 8 0 1 7 1
80 52 16 0 1 3 4 9 1 2 5 1
81 29 16 0 0 3 2 9 1 1 10 1
82 28 16 1 0 3 4 1 8 1 2 5 1
83 63 16 0 1 3 4 5 10 1 2 1
84 84 30 1 0 1 4 2 8 0 2 4 1
85 31 30 0 1 3 4 1 8 0 1 9 1
86 46 30 1 1 1 5 5 9 1 1 3 1
87 84 30 0 0 3 5 10 1 1 6 1
88 30 31 0 0 2 3 1 9 0 2 7 1
89 29 31 1 0 1 4 1 9 1 1 7 1
90 46 31 1 1 3 3 10 0 2 5 1
91 17 17 1 0 1 15 1 7 2 1 8 2
92 37 17 0 0 2 14 4 7 2 1 10 2
93 43 17 0 0 3 14 1 10 1 1 6 2
94 57 17 1 0 2 13 1 10 1 2 6 2
95 58 17 1 1 3 14 1 10 2 2 4 2
96 59 17 0 1 3 15 4 7 1 1 1 2
97 26 18 0 0 3 13 2 7 2 2 7 2
98 43 18 0 0 3 15 1 7 1 1 2
99 66 18 0 1 1 13 2 7 1 1 8 2
100 85 20 1 0 2 14 1 8 3 2 2
101 20 1 13 7 3 2
102 21 1 15 5 1 2
103 21 0 13 6 2 2
104 30 0 13 6 2 2
105 30 0 15 5 1 2
106 30 0 14 6 1 2
107 31 0 15 5 1 2
108 31 1 15 4 2 2
109 31 1 14 6 2 2
110 31 1 14 5 0 2
111 20 1 10 3 0 3
112 20 1 9 4 0 3
113 21 1 10 3 0 3
114 21 0 9 4 0 3
115 21 0 10 5 0 3
116 30 0 10 5 0 3
117 40 0 10 5 0 3
118 50 0 10 5 0 3
119 65 0 10 5 0 3
120 21 0 11 4 5 4
121 22 1 11 4 5 4

View File

@ -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))

View File

@ -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()

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 KiB