zapisywanie drzewa do pliku, zmienienie prędkości głodu

This commit is contained in:
Frania 2024-05-13 12:49:19 +02:00
parent ad6fd4bc1b
commit dbdb7b6b7d
10 changed files with 20 additions and 22 deletions

View File

@ -16,7 +16,7 @@ class Bat(Animal):
def getting_hungry(self, const):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 35*5
minutes_passed = delta.total_seconds() / (25)
self._starttime = checktime
if const.IS_NIGHT and self._feed < 10:

View File

@ -18,7 +18,7 @@ class Bear(Animal):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 60*5
minutes_passed = delta.total_seconds() / (45)
self._starttime = checktime
if const.IS_NIGHT and self._feed < 10 and const.season != "winter":

View File

@ -22,7 +22,7 @@ class Elephant(Animal):
def getting_hungry(self, const):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 50*5
minutes_passed = delta.total_seconds() / (90)
self._starttime = checktime
if not const.IS_NIGHT and self._feed < 10:

View File

@ -17,7 +17,7 @@ class Giraffe(Animal):
def getting_hungry(self, const):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 35*5
minutes_passed = delta.total_seconds() / (60)
self._starttime = checktime
if not const.IS_NIGHT and self._feed < 10:

View File

@ -16,7 +16,7 @@ class Owl(Animal):
def getting_hungry(self, const):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 30*5
minutes_passed = delta.total_seconds() / (50)
self._starttime = checktime
if const.IS_NIGHT and self._feed < 10:

View File

@ -17,7 +17,7 @@ class Parrot(Animal):
def getting_hungry(self, const):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 25*5
minutes_passed = delta.total_seconds() / (30)
self._starttime = checktime
if not const.IS_NIGHT and self._feed < 10:

View File

@ -17,7 +17,7 @@ class Penguin(Animal):
def getting_hungry(self, const):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 20*5
minutes_passed = delta.total_seconds() / (25)
self._starttime = checktime
if not const.IS_NIGHT and self._feed < 10:

View File

@ -9,7 +9,7 @@ False,True,False,summer,2,9.07977,22.08011,20.53507,3
False,False,True,winter,11,3.5635,14.75823,43.46342,2
False,False,True,winter,9,8.03113,20.6384,30.81177,2
True,True,True,summer,0,0.01966,28.27203,3.37575,1
False,False,False,autumn,12,8.27518,5.91931,21.10505,3
False,False,False,autumn,12,8.27518,5.91931,1.10505,2
False,False,True,summer,1,5.058,11.01892,48.04589,3
False,True,False,winter,9,5.64777,17.19678,12.20864,1
True,True,True,summer,0,6.86046,19.03315,47.13198,3
@ -49,7 +49,7 @@ False,False,True,autumn,5,7.85569,40.47073,49.75818,2
True,False,True,summer,1,9.03492,23.44692,20.0026,3
False,True,True,autumn,8,2.36724,42.81768,21.34668,2
False,False,True,summer,15,6.8222,15.2733,15.14799,3
True,False,True,summer,4,8.63882,41.36166,17.98981,3
True,False,True,summer,4,8.63882,41.36166,7.98981,2
False,True,False,autumn,12,0.48943,8.67832,40.4952,1
False,False,False,autumn,3,3.0489,14.81219,8.32707,1
False,True,True,winter,6,0.41014,49.94757,12.61713,1
@ -73,7 +73,7 @@ False,False,False,summer,3,7.36268,28.50462,29.52973,1
True,True,True,spring,3,6.1319,37.71758,33.50616,1
False,True,True,spring,0,0.77228,42.89976,19.19004,1
True,False,True,autumn,3,7.73055,20.87865,37.18248,1
False,False,False,summer,1,8.30392,34.47046,34.77926,3
False,False,False,summer,1,8.30392,34.47046,8.77926,2
True,True,False,summer,8,2.96562,17.50839,23.22476,1
True,True,True,winter,4,2.27279,20.58575,32.17293,1
True,False,True,spring,7,6.14608,34.46015,17.22245,1

1 adult active_time ill season guests hunger wet_food dry_food decision
9 False False True winter 11 3.5635 14.75823 43.46342 2
10 False False True winter 9 8.03113 20.6384 30.81177 2
11 True True True summer 0 0.01966 28.27203 3.37575 1
12 False False False autumn 12 8.27518 5.91931 21.10505 1.10505 3 2
13 False False True summer 1 5.058 11.01892 48.04589 3
14 False True False winter 9 5.64777 17.19678 12.20864 1
15 True True True summer 0 6.86046 19.03315 47.13198 3
49 True False True summer 1 9.03492 23.44692 20.0026 3
50 False True True autumn 8 2.36724 42.81768 21.34668 2
51 False False True summer 15 6.8222 15.2733 15.14799 3
52 True False True summer 4 8.63882 41.36166 17.98981 7.98981 3 2
53 False True False autumn 12 0.48943 8.67832 40.4952 1
54 False False False autumn 3 3.0489 14.81219 8.32707 1
55 False True True winter 6 0.41014 49.94757 12.61713 1
73 True True True spring 3 6.1319 37.71758 33.50616 1
74 False True True spring 0 0.77228 42.89976 19.19004 1
75 True False True autumn 3 7.73055 20.87865 37.18248 1
76 False False False summer 1 8.30392 34.47046 34.77926 8.77926 3 2
77 True True False summer 8 2.96562 17.50839 23.22476 1
78 True True True winter 4 2.27279 20.58575 32.17293 1
79 True False True spring 7 6.14608 34.46015 17.22245 1

View File

@ -1,5 +1,5 @@
import pandas as pd
from sklearn.tree import DecisionTreeClassifier, plot_tree, export_graphviz
from sklearn.tree import DecisionTreeClassifier, plot_tree
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
@ -9,24 +9,22 @@ data = pd.read_csv('dane.csv', header=0)
X = data[headers]
Y = data['decision']
X = pd.get_dummies(data=X, columns=['season'])
clf = DecisionTreeClassifier(random_state=0, min_samples_leaf = 4, min_samples_split=2)
clf = clf.fit(X,Y)
#skuteczność drzewa
'''
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, train_size=0.8)
clf = clf.fit(X_train, Y_train)
Y_pred = clf.predict(X_test)
accuracy = accuracy_score(Y_test, Y_pred)
clf = DecisionTreeClassifier(max_depth=6)
X1, X2, Y1, Y2 = train_test_split(X, Y, train_size=0.8)
clf = clf.fit(X1, Y1)
pred = clf.predict(X2)
accuracy = accuracy_score(Y2, pred)
print("Dokładność:", accuracy)
'''
#zapisanie drzewa do pliku
plt.figure(figsize=(50,30))
plot_tree(clf, filled=True, feature_names=X.columns, class_names=['nie karmi', 'karmi mokrą karmą', 'karmi suchą karmą'])
plot_tree(clf, filled=True, feature_names=X.columns.tolist(), class_names=['nie karmi', 'karmi mokrą karmą', 'karmi suchą karmą'])
plt.savefig('tree.png')
# dane do decyzji
def feed_decision(adult,active_time,ill,season,guests,hunger,dry_food,wet_food):
X_new = pd.DataFrame({
'adult': [adult],
'active_time': [active_time],

BIN
tree.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 655 KiB

After

Width:  |  Height:  |  Size: 613 KiB