Algorytm_genetyczny #3

Merged
s481832 merged 18 commits from Algorytm_genetyczny into master 2024-06-10 13:30:20 +02:00
14 changed files with 418 additions and 42 deletions
Showing only changes of commit b0175f56d7 - Show all commits

View File

@ -47,6 +47,7 @@ class Animal:
chance = random.randint(1, 100)
if chance >= 90:
return True
else: return False
def draw_illness(self, screen, grid_size, x, y):
scale = 0.45

View File

@ -46,18 +46,18 @@ def draw_Animals(Animals, const):
Animal.draw(const.screen, const.GRID_SIZE)
if Animal.getting_hungry(const) == 5:
if Animal.getting_hungry(const) == 10:
Animal.draw_exclamation(const.screen, const.GRID_SIZE, Animal.x, Animal.y)
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/empty_bowl.png')
if Animal.getting_hungry(const) >= 4 and Animal.getting_hungry(const) < 5:
if Animal.getting_hungry(const) >= 8 and Animal.getting_hungry(const) < 5:
Animal.draw_exclamation(const.screen, const.GRID_SIZE, Animal.x, Animal.y)
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/almost_empty.png')
if Animal.getting_hungry(const) >= 2 and Animal.getting_hungry(const) < 4:
if Animal.getting_hungry(const) >= 5 and Animal.getting_hungry(const) < 4:
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/half_bowl.png')
if Animal.getting_hungry(const) < 2:
if Animal.getting_hungry(const) < 5:
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/full_bowl.png')
if Animal.ill:

View File

@ -9,6 +9,7 @@ class Bat(Animal):
environment = "medium"
food_image = 'images/grains.png'
parrot_food = 'grains'
activity = 'nocturnal'
super().__init__(x, y,name, Bat_image, food_image,parrot_food, environment, adult)
self._starttime = datetime.now()
@ -18,8 +19,8 @@ class Bat(Animal):
minutes_passed = delta.total_seconds() / 30
self._starttime = checktime
if const.IS_NIGHT and self._feed < 5:
if const.IS_NIGHT and self._feed < 10:
self._feed += minutes_passed
self._feed = min(self._feed, 5)
self._feed = min(self._feed, 10)
return self._feed

View File

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

View File

@ -25,7 +25,7 @@ class Elephant(Animal):
minutes_passed = delta.total_seconds() / 50
self._starttime = checktime
if not const.IS_NIGHT and self._feed < 5:
if not const.IS_NIGHT and self._feed < 10:
self._feed += minutes_passed
self._feed = min(self._feed, 5)
self._feed = min(self._feed, 10)
return self._feed

View File

@ -20,7 +20,7 @@ class Giraffe(Animal):
minutes_passed = delta.total_seconds() / 30
self._starttime = checktime
if not const.IS_NIGHT and self._feed < 5:
if not const.IS_NIGHT and self._feed < 10:
self._feed += minutes_passed
self._feed = min(self._feed, 5)
self._feed = min(self._feed, 10)
return self._feed

View File

@ -9,6 +9,7 @@ class Owl(Animal):
environment = "medium"
food_image = 'images/grains.png'
parrot_food = 'grains'
activity = 'nocturnal'
super().__init__(x, y,name, Owl_image, food_image,parrot_food, environment, adult)
self._starttime = datetime.now()
@ -18,8 +19,8 @@ class Owl(Animal):
minutes_passed = delta.total_seconds() / 25
self._starttime = checktime
if const.IS_NIGHT and self._feed < 5:
if const.IS_NIGHT and self._feed < 10:
self._feed += minutes_passed
self._feed = min(self._feed, 5)
self._feed = min(self._feed, 10)
return self._feed

View File

@ -20,7 +20,7 @@ class Parrot(Animal):
minutes_passed = delta.total_seconds() / 20
self._starttime = checktime
if not const.IS_NIGHT and self._feed < 5:
if not const.IS_NIGHT and self._feed < 10:
self._feed += minutes_passed
self._feed = min(self._feed, 5)
self._feed = min(self._feed, 10)
return self._feed

View File

@ -20,7 +20,7 @@ class Penguin(Animal):
minutes_passed = delta.total_seconds() / 15
self._starttime = checktime
if not const.IS_NIGHT and self._feed < 5:
if not const.IS_NIGHT and self._feed < 10:
self._feed += minutes_passed
self._feed = min(self._feed, 5)
self._feed = min(self._feed, 10)
return self._feed

View File

@ -1,7 +1,10 @@
import pygame
import random
from constants import Constants
from state_space_search import is_border, is_obstacle
from night import draw_night
from decision_tree import add_data
from constants import Constants
class Agent:
def __init__(self, istate, image_path, grid_size):
@ -10,7 +13,8 @@ class Agent:
self.grid_size = grid_size
self.image= pygame.image.load(image_path)
self.image = pygame.transform.scale(self.image, (grid_size, grid_size))
self._food = 0
self._dryfood = 0
self._wetfood = 0
def draw(self, const):
# Obróć obrazek zgodnie z kierunkiem
@ -27,16 +31,16 @@ class Agent:
if const.IS_NIGHT: draw_night(const)
def handle_event(self, event, max_x, max_y, animals, obstacles):
def handle_event(self, event, max_x, max_y, animals, obstacles,const):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
self.move('Go Forward', max_x, max_y, obstacles, animals)
self.move('Go Forward', max_x, max_y, obstacles, animals,const)
elif event.key == pygame.K_LEFT:
self.move('Turn Left', max_x, max_y, obstacles, animals)
self.move('Turn Left', max_x, max_y, obstacles, animals,const)
elif event.key == pygame.K_RIGHT:
self.move('Turn Right', max_x, max_y, obstacles, animals)
self.move('Turn Right', max_x, max_y, obstacles, animals,const)
def move(self, action, max_x, max_y, obstacles, animals, goal):
def move(self, action, max_x, max_y, obstacles, animals, goal,const):
if action == 'Go Forward':
new_x, new_y = self.x, self.y
if self.direction == 'N':
@ -59,29 +63,47 @@ class Agent:
self.direction = {'N': 'E', 'E': 'S', 'S': 'W', 'W': 'N'}[self.direction]
self.istate = (self.x, self.y, self.direction)
feed_animal(self, animals, goal)
feed_animal(self, animals, goal,const)
take_food(self)
def feed_animal(self, animals, goal):
def feed_animal(self, animals, goal,const):
goal_x, goal_y = goal
if self.x == goal_x and self.y == goal_y:
for animal in animals:
if animal.x == goal_x and animal.y == goal_y:
if animal.getting_hungry(const=Constants()) < self._food :
self._food -= animal._feed
animal._feed = 0
print(animal.name, "fed with", animal.food)
print("Current food level: ", self._food)
if (animal.activity == 'nocturnal' and const.IS_NIGHT) or (animal.activity == 'diurnal' and not(const.IS_NIGHT)):
activity_time = True
else:
animal._feed -= self._food
self._food = 0
print(animal.name, "fed with", animal.food)
print("Current food level: ", self._food)
activity_time = False
guests = random.randint(1, 15)
feed_decision = add_data(animal.adult, activity_time, animal.ill, const.season, guests, animal._feed, self._dryfood, self._wetfood)
if feed_decision != 1:
if feed_decision == 2:
if animal.getting_hungry(const=Constants()) < self._wetfood :
self._wetfood -= animal._feed
animal._feed = 0
else:
animal._feed -= self._wetfood
self._food = 0
print(animal.name, "fed with wet food")
else:
if animal.getting_hungry(const=Constants()) < self._dryfood :
self._dryfood -= animal._feed
animal._feed = 0
else:
animal._feed -= self._dryfood
self._dryfood = 0
print(animal.name, "fed with dry food")
print("Current wet food level: ", self._wetfood)
print("Current dry food level: ", self._dryfood)
else: print(animal.name, " not fed")
def take_food(self):
house_x = 3
house_y = 1
if self.x == house_x and self.y == house_y:
if self._food == 0:
self._food = 25
print("Agent took food and current food level is", self._food)
if self._dryfood == 0 and self._wetfood == 0:
self._dryfood = 50
self._wetfood = 50
print("Agent took food and current food level is", self._dryfood, self._wetfood)

301
dane.csv Normal file
View File

@ -0,0 +1,301 @@
adult,active_time,ill,season,guests,hunger,wet_food,dry_food,decision
True,True,True,spring,12,4.0462,37.63803,5.60819,2
True,False,False,spring,9,2.89229,34.37597,27.75948,1
False,True,True,summer,15,2.4002,45.06447,41.50999,3
True,False,False,summer,5,0.73248,46.1058,33.44281,1
True,False,False,summer,12,0.62973,49.99647,41.07699,1
True,False,False,winter,9,7.0889,46.16796,45.904,2
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,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
True,False,True,winter,13,0.42516,12.62312,19.15853,1
True,False,True,summer,14,4.46951,33.59537,47.343,1
True,True,False,autumn,11,6.49386,0.64398,1.0515,1
False,False,False,winter,10,1.9354,22.80015,26.01165,1
True,False,False,summer,7,3.55716,1.91094,41.82462,1
False,True,True,winter,8,9.01072,15.89341,9.10422,2
False,True,True,spring,4,4.64513,10.39766,7.57955,2
True,False,False,autumn,2,4.11019,45.85039,30.34183,1
True,True,True,spring,8,7.09003,6.92577,24.77301,3
True,True,False,spring,6,4.12955,47.91516,12.84722,1
True,True,True,spring,10,2.70845,1.0623,42.6941,3
True,True,True,spring,15,4.34025,6.89381,3.03923,2
True,False,False,autumn,5,7.24464,31.34759,6.44719,1
True,True,True,summer,6,3.8924,18.08964,18.77435,1
False,False,True,spring,13,4.86962,48.62578,6.05301,2
False,True,False,spring,11,1.60186,31.34926,14.41007,2
False,True,False,autumn,2,4.19839,19.58116,28.63919,1
False,True,True,autumn,6,1.50346,25.88282,24.97486,1
False,True,False,spring,7,2.67431,17.05587,24.7939,1
True,True,True,spring,7,1.72828,38.17304,24.3685,1
False,True,True,summer,12,7.55322,26.52797,42.24754,3
False,True,False,summer,5,8.74993,30.39317,4.5676,2
False,True,False,summer,5,7.42862,48.73014,5.94891,2
True,False,False,spring,4,9.3662,12.90556,41.31266,3
False,True,False,autumn,8,4.72785,0.1623,19.48377,1
False,False,False,winter,14,6.49349,29.52121,21.87192,1
True,False,False,summer,14,1.57899,26.90783,33.03528,1
False,True,False,summer,3,6.21725,3.60564,23.51978,1
True,True,True,winter,4,4.18565,25.24209,11.02056,1
False,False,True,autumn,8,6.5479,39.16107,4.75438,2
False,False,False,summer,13,2.14609,39.97177,13.98651,1
True,True,False,winter,9,7.43651,10.09353,15.70939,3
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
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
True,False,True,winter,12,5.55017,0.98544,10.25287,1
True,False,False,summer,11,9.92135,6.80759,48.0665,3
False,True,True,winter,2,7.14394,11.41862,18.29288,2
False,True,True,winter,10,1.39924,36.41807,42.95548,2
False,True,False,summer,1,0.95193,46.53851,25.70391,1
False,True,False,winter,4,1.44658,6.61497,31.58116,1
False,True,False,autumn,10,7.9404,26.82316,49.5898,2
True,False,False,spring,5,5.14951,32.36345,11.32114,1
True,True,False,summer,5,7.55665,49.12578,29.32983,3
True,False,True,autumn,3,3.80646,11.86722,35.43034,1
False,False,False,winter,12,3.65822,0.14026,19.18031,1
True,False,False,spring,8,8.58384,46.33595,11.52974,2
True,False,False,summer,3,6.34127,22.66891,19.15813,1
False,True,False,spring,13,7.86448,8.85557,40.03913,3
True,True,False,spring,13,8.89316,49.89548,21.04525,2
True,True,False,autumn,9,0.91339,36.35922,16.09576,1
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
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
False,False,True,winter,1,8.32044,12.09058,37.28732,3
False,True,False,spring,14,9.56618,48.49473,46.37651,2
True,False,True,spring,10,9.33146,47.99213,35.92519,2
False,True,False,spring,6,0.47396,37.45415,36.87019,1
True,False,False,summer,12,7.61463,4.36339,36.07375,3
True,True,True,autumn,3,6.42039,4.90383,43.29857,3
False,True,False,winter,13,6.89007,43.09184,3.04284,2
True,False,True,winter,1,6.56604,19.04681,27.58314,2
True,False,True,spring,3,1.96784,2.18597,34.02966,1
False,False,False,spring,0,3.76673,1.64674,34.50649,1
False,False,True,summer,2,0.05382,10.48896,24.03557,1
True,False,True,spring,14,5.12387,44.44585,8.35502,3
True,True,False,autumn,10,4.90335,43.27857,27.22901,1
True,False,False,winter,11,5.89082,28.91495,15.58095,1
True,False,True,autumn,3,7.39589,21.53402,44.50694,3
True,False,False,summer,12,5.68671,49.18777,22.53807,3
False,False,False,winter,0,0.86765,41.28704,33.77284,1
False,False,True,summer,10,5.97643,36.23669,48.32615,2
False,True,True,autumn,7,1.76947,38.34692,13.28679,1
True,True,True,summer,13,8.63622,16.14861,44.91355,3
True,False,False,winter,11,8.48481,37.52722,47.76888,2
True,True,True,summer,12,7.65812,4.16785,34.57922,3
False,False,True,winter,7,8.44897,42.99815,44.66558,2
False,False,False,winter,7,0.53067,13.47003,18.45329,1
False,False,False,winter,14,3.24747,9.51144,6.62824,1
True,True,False,spring,12,5.19071,47.53107,34.68942,2
True,False,False,summer,9,6.9442,46.79146,13.92798,2
True,False,False,autumn,1,3.09242,18.02023,11.03004,1
True,True,True,spring,3,0.19271,1.00203,1.16671,1
False,True,True,winter,5,9.00758,37.95091,11.54697,2
True,False,True,spring,9,6.11904,37.42698,4.82627,2
False,False,True,autumn,9,6.29507,22.99044,15.46992,2
False,False,False,winter,13,5.4099,11.75134,6.91861,1
False,False,False,winter,5,9.92035,21.82547,10.2415,2
False,True,False,winter,10,6.06913,1.46795,12.76663,1
True,False,True,spring,5,8.1218,37.03643,32.04156,3
True,False,False,autumn,11,0.48844,39.36689,0.03464,1
False,True,True,summer,6,1.72816,26.85829,16.53262,1
False,False,False,spring,5,6.04025,29.55673,18.85232,2
False,True,True,winter,2,1.75157,0.6601,49.91163,1
False,True,True,winter,9,6.75125,15.22221,6.72688,2
False,True,True,autumn,9,6.72535,24.07403,33.94074,2
False,False,False,winter,14,0.02843,48.49973,15.81701,1
False,False,True,autumn,15,1.07944,45.94025,4.05257,1
False,False,True,winter,12,7.26288,15.82501,22.56163,2
True,True,True,winter,11,8.50892,23.89966,46.14267,3
True,False,True,autumn,11,8.10923,24.31448,6.70919,2
True,True,False,summer,11,4.65313,3.44791,3.96313,3
True,False,True,summer,2,2.56716,10.85536,49.88738,1
False,False,True,autumn,4,8.19265,5.43942,48.74041,3
False,True,False,autumn,5,5.6574,9.75738,25.96888,3
False,True,False,winter,14,4.87066,33.40134,18.98246,2
True,True,True,winter,6,8.2623,37.47298,33.76759,2
True,True,True,spring,10,2.20409,13.6178,5.80078,2
True,False,True,autumn,7,9.06057,37.8724,23.62209,2
False,False,True,autumn,3,6.69861,37.07336,16.87187,2
True,False,True,autumn,13,4.96475,46.87852,3.1412,1
True,False,True,autumn,9,2.65212,19.06994,37.33364,1
True,True,False,summer,15,3.47148,35.84529,0.00000,1
False,True,True,summer,8,1.51025,9.44246,19.05913,1
False,False,True,autumn,6,6.48485,45.61986,15.91179,2
False,False,False,spring,2,8.98075,39.32941,42.47669,2
False,True,True,winter,5,8.37177,12.99299,42.31566,3
True,True,True,autumn,6,3.38746,48.86975,49.62605,1
False,True,True,summer,7,7.09358,22.83074,38.5172,2
False,False,True,spring,9,1.00148,11.16064,0.52706,1
False,False,True,winter,1,6.08476,37.67744,4.49812,2
False,True,False,spring,5,4.5182,32.48803,33.44274,1
True,True,True,summer,8,6.11265,30.32015,46.47287,3
False,True,True,winter,4,8.50937,22.72015,0.00000,2
True,False,True,summer,4,7.23924,39.09963,42.82872,3
False,False,True,summer,5,1.28353,7.18667,38.93923,1
False,True,False,spring,3,4.50329,22.95269,0.41795,1
True,True,True,summer,1,0.47824,14.79432,24.64273,1
False,True,False,spring,10,8.43205,19.1333,20.95803,2
False,True,False,spring,6,9.94659,18.83814,39.26147,2
False,True,False,spring,3,3.68802,1.58951,26.4255,1
False,False,True,autumn,8,4.79336,22.56564,4.95207,2
False,True,True,spring,10,1.63541,0.00000,31.82704,1
False,True,False,spring,2,1.2274,47.87731,32.98744,1
True,True,False,winter,11,7.31457,26.08142,16.5835,2
False,True,True,summer,2,4.90627,19.73976,49.56272,3
True,True,False,winter,8,3.02707,35.9547,29.52088,1
True,True,True,summer,7,5.02577,5.37674,16.61368,3
False,False,True,spring,8,9.58805,8.12549,0.00000,2
False,True,True,summer,6,2.08786,37.11126,36.15777,3
True,True,False,spring,7,8.11839,12.2032,8.26737,2
True,False,True,summer,7,4.08923,20.77025,11.25944,1
False,False,True,winter,4,4.85557,0.00000,39.4493,2
False,False,False,summer,14,9.12718,41.84025,49.51895,2
True,True,True,summer,15,9.4014,34.10345,26.84361,3
False,True,False,spring,14,8.61728,28.58017,39.3705,2
False,True,False,winter,8,7.12808,12.04193,43.86622,2
True,False,True,winter,1,9.50102,43.46168,28.81571,2
True,True,False,spring,5,1.35366,6.95688,33.37058,1
False,False,True,autumn,11,7.61014,11.10761,41.58039,2
False,True,True,summer,2,6.86814,37.72905,14.64706,3
True,False,False,winter,1,8.12812,22.55081,9.43532,2
True,True,True,winter,10,4.18282,27.82423,30.42216,1
False,False,False,summer,7,2.52646,3.74242,10.61286,1
False,False,True,spring,13,3.15065,19.01632,34.56097,2
True,True,False,summer,3,0.18108,46.67684,46.76693,1
True,True,True,spring,0,1.50217,5.27541,16.18378,1
False,True,True,summer,5,3.71758,11.15496,12.57224,3
False,True,False,summer,6,9.92613,8.59078,21.32207,3
True,False,False,winter,11,0.1261,2.42716,17.23296,1
True,False,True,summer,14,6.90049,10.76539,3.92394,3
False,True,True,autumn,15,1.76164,35.60051,2.5168,2
False,False,True,spring,11,2.39225,36.14198,9.13906,3
True,True,False,summer,2,4.04026,0.00000,12.47216,1
True,True,False,spring,13,3.32803,7.59913,1.89442,3
True,False,True,spring,1,5.15927,44.02139,4.03454,1
True,True,True,autumn,13,5.52565,7.75133,38.62709,3
True,True,False,spring,3,8.44216,30.01593,12.45777,3
False,False,True,summer,13,2.88557,5.18905,5.87065,3
True,True,True,spring,11,2.45261,7.22671,49.68806,3
True,True,True,winter,4,8.55814,3.29899,32.82852,2
False,False,True,summer,4,9.85169,47.62867,17.3155,3
False,False,True,winter,2,5.30151,26.50068,48.79306,2
False,False,False,autumn,9,7.59806,0.00000,36.92142,2
False,True,True,autumn,1,9.28424,17.58014,28.42461,2
True,False,True,summer,14,7.82306,35.29264,46.36975,3
False,False,True,winter,2,1.10909,46.37088,40.88245,1
True,True,False,summer,1,7.71442,43.2301,27.42849,3
False,True,True,summer,6,1.21255,3.7357,4.31858,1
True,True,True,winter,8,9.53076,12.54774,17.63524,2
True,True,True,autumn,3,8.47955,19.04656,3.62988,2
True,False,True,winter,3,2.58264,28.29242,0.00000,1
True,False,False,autumn,5,6.83145,0.00000,15.88102,1
True,False,False,summer,10,3.24742,16.50963,26.24036,1
False,False,False,summer,8,8.66174,49.55046,33.2433,2
True,False,True,winter,7,1.40722,4.06585,2.57929,1
False,True,False,winter,12,4.483,2.42211,20.55941,2
False,False,True,spring,12,2.98512,30.55243,5.53733,3
False,False,True,autumn,6,0.84086,33.57311,32.42908,1
False,True,True,winter,12,1.07916,8.27438,7.9284,1
False,False,True,spring,12,3.17402,46.59657,14.21739,3
False,True,True,winter,11,7.09559,14.18261,43.41709,2
False,False,True,autumn,3,0.53006,21.37664,17.14295,1
False,False,False,autumn,14,4.67143,4.11788,0.04226,1
True,False,True,winter,12,3.48493,35.24303,0.00000,1
True,True,True,spring,9,5.1789,0.97673,8.31413,2
False,False,False,spring,5,1.50319,28.57762,27.80054,1
True,True,True,autumn,10,9.23444,43.51842,19.90954,2
False,False,False,autumn,9,3.84582,40.34953,9.01663,1
True,True,False,winter,5,3.90587,32.97826,0.67046,1
True,True,True,autumn,2,9.19994,0.00000,34.36662,3
False,True,True,summer,6,5.614,29.08038,0.00000,2
True,True,True,autumn,2,2.15339,6.36751,6.45082,1
True,False,True,spring,1,9.19416,32.05433,8.27667,2
True,False,True,autumn,0,8.12282,48.68677,8.38304,2
False,True,True,spring,12,3.26729,29.61584,1.69993,2
True,False,True,summer,8,1.99886,31.26437,3.51834,1
False,False,True,summer,7,7.41314,44.88982,34.46453,2
True,False,True,summer,0,7.24464,8.85289,34.29828,3
False,True,False,summer,8,2.38628,21.76861,47.20283,3
True,True,True,autumn,3,7.12112,12.08359,41.06062,3
True,False,False,winter,5,6.74504,47.09367,1.97357,2
False,False,False,summer,8,1.23539,35.47945,7.67276,1
True,False,False,spring,11,7.91742,34.52557,30.96412,3
False,True,True,winter,14,5.91181,7.53226,16.37669,3
False,True,True,spring,13,6.07261,47.43572,15.83885,2
True,True,True,autumn,2,9.22518,31.25996,28.06488,3
False,True,True,summer,3,8.47609,0.23934,31.25786,3
False,True,False,autumn,6,0.97126,13.65648,25.59887,1
True,False,False,spring,14,9.29029,46.83676,12.58912,2
False,False,False,winter,14,0.14092,4.6673,20.3859,1
True,False,True,autumn,2,3.52708,37.61372,32.83573,1
True,True,True,winter,1,4.37134,43.19138,22.04785,1
True,False,True,summer,9,1.1614,10.9739,42.3009,1
False,False,False,winter,9,7.27324,29.74731,47.17759,2
False,True,True,winter,9,3.17153,35.14715,21.37868,2
False,True,False,autumn,0,2.37863,20.35733,46.96943,1
False,False,True,autumn,4,0.70656,8.70201,5.26527,1
True,True,True,winter,1,8.23562,36.01552,25.03969,2
True,True,False,winter,3,6.65062,6.75622,24.91086,3
False,False,False,spring,10,2.30179,19.62758,25.57147,1
True,True,False,autumn,10,6.60812,6.61336,12.39931,3
False,False,True,summer,3,8.9948,47.39225,18.11157,2
True,False,True,autumn,5,6.69302,42.62701,13.01677,2
False,False,False,spring,14,8.53868,33.42545,2.43572,2
False,True,True,autumn,10,4.46205,10.37542,39.58137,3
True,True,False,spring,14,5.34262,15.45545,21.48404,3
True,False,False,winter,9,7.02885,4.88308,27.56619,3
False,False,False,autumn,13,3.55279,0.17091,5.43831,1
True,True,True,autumn,1,9.98637,27.57982,15.82173,2
False,True,True,summer,9,8.25408,13.10493,27.07596,3
False,False,False,spring,15,1.9089,33.25115,44.57492,1
True,False,False,autumn,12,6.65534,38.00972,20.31047,2
False,True,True,autumn,1,0.01592,6.24929,15.51308,1
False,True,True,winter,13,1.24017,36.88006,16.50894,1
False,True,True,winter,13,6.1878,15.18876,9.02381,2
True,True,True,winter,5,5.45157,13.27868,39.39805,2
True,False,True,spring,5,2.82881,28.62319,24.03077,1
False,False,True,spring,2,4.8246,41.45269,48.89539,2
True,False,False,spring,8,9.3343,39.02018,45.01066,3
True,True,True,autumn,4,1.8456,2.94366,37.44996,1
False,True,True,summer,14,0.95333,4.57964,26.37633,1
False,False,True,autumn,13,9.84087,24.03819,41.72097,2
True,False,False,autumn,9,3.70617,32.70115,1.69105,1
True,True,True,spring,12,6.77783,6.67976,20.46179,3
False,False,True,summer,15,7.15829,31.24546,10.37666,3
False,True,True,summer,1,2.28393,18.13299,34.38756,3
True,False,True,autumn,7,3.96302,39.84093,47.0172,1
True,False,False,summer,1,0.65085,20.20581,14.96995,1
True,False,False,winter,2,9.24331,26.34543,30.5147,2
True,False,False,summer,3,2.86309,15.56342,1.04324,1
True,False,False,summer,1,4.03947,33.84073,6.48891,1
True,False,False,winter,4,2.46471,24.07929,17.77792,1
False,False,False,winter,9,3.66415,23.68306,24.43865,1
True,True,True,autumn,8,5.71809,24.41045,48.78273,2
False,True,True,spring,3,5.3009,34.83862,6.75862,2
True,False,True,winter,8,6.23275,8.1183,19.6922,3
False,True,True,autumn,2,4.21016,11.24334,34.98395,3
True,True,False,autumn,0,2.79424,13.25106,5.69617,1
True,True,False,winter,15,2.43843,14.61703,49.57393,2
True,True,True,summer,8,2.28654,20.9895,5.64007,1
False,False,False,autumn,1,2.5607,26.85209,47.10784,1
True,True,True,winter,14,1.56638,18.02703,7.05011,1
False,False,False,winter,13,3.86632,28.9884,20.1928,1
True,False,False,summer,13,6.37654,34.3833,34.53892,3
True,True,False,summer,5,8.10422,7.6617,23.41017,3
1 adult active_time ill season guests hunger wet_food dry_food decision
2 True True True spring 12 4.0462 37.63803 5.60819 2
3 True False False spring 9 2.89229 34.37597 27.75948 1
4 False True True summer 15 2.4002 45.06447 41.50999 3
5 True False False summer 5 0.73248 46.1058 33.44281 1
6 True False False summer 12 0.62973 49.99647 41.07699 1
7 True False False winter 9 7.0889 46.16796 45.904 2
8 False True False summer 2 9.07977 22.08011 20.53507 3
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 3
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
16 True False True winter 13 0.42516 12.62312 19.15853 1
17 True False True summer 14 4.46951 33.59537 47.343 1
18 True True False autumn 11 6.49386 0.64398 1.0515 1
19 False False False winter 10 1.9354 22.80015 26.01165 1
20 True False False summer 7 3.55716 1.91094 41.82462 1
21 False True True winter 8 9.01072 15.89341 9.10422 2
22 False True True spring 4 4.64513 10.39766 7.57955 2
23 True False False autumn 2 4.11019 45.85039 30.34183 1
24 True True True spring 8 7.09003 6.92577 24.77301 3
25 True True False spring 6 4.12955 47.91516 12.84722 1
26 True True True spring 10 2.70845 1.0623 42.6941 3
27 True True True spring 15 4.34025 6.89381 3.03923 2
28 True False False autumn 5 7.24464 31.34759 6.44719 1
29 True True True summer 6 3.8924 18.08964 18.77435 1
30 False False True spring 13 4.86962 48.62578 6.05301 2
31 False True False spring 11 1.60186 31.34926 14.41007 2
32 False True False autumn 2 4.19839 19.58116 28.63919 1
33 False True True autumn 6 1.50346 25.88282 24.97486 1
34 False True False spring 7 2.67431 17.05587 24.7939 1
35 True True True spring 7 1.72828 38.17304 24.3685 1
36 False True True summer 12 7.55322 26.52797 42.24754 3
37 False True False summer 5 8.74993 30.39317 4.5676 2
38 False True False summer 5 7.42862 48.73014 5.94891 2
39 True False False spring 4 9.3662 12.90556 41.31266 3
40 False True False autumn 8 4.72785 0.1623 19.48377 1
41 False False False winter 14 6.49349 29.52121 21.87192 1
42 True False False summer 14 1.57899 26.90783 33.03528 1
43 False True False summer 3 6.21725 3.60564 23.51978 1
44 True True True winter 4 4.18565 25.24209 11.02056 1
45 False False True autumn 8 6.5479 39.16107 4.75438 2
46 False False False summer 13 2.14609 39.97177 13.98651 1
47 True True False winter 9 7.43651 10.09353 15.70939 3
48 False False True autumn 5 7.85569 40.47073 49.75818 2
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 3
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
56 True False True winter 12 5.55017 0.98544 10.25287 1
57 True False False summer 11 9.92135 6.80759 48.0665 3
58 False True True winter 2 7.14394 11.41862 18.29288 2
59 False True True winter 10 1.39924 36.41807 42.95548 2
60 False True False summer 1 0.95193 46.53851 25.70391 1
61 False True False winter 4 1.44658 6.61497 31.58116 1
62 False True False autumn 10 7.9404 26.82316 49.5898 2
63 True False False spring 5 5.14951 32.36345 11.32114 1
64 True True False summer 5 7.55665 49.12578 29.32983 3
65 True False True autumn 3 3.80646 11.86722 35.43034 1
66 False False False winter 12 3.65822 0.14026 19.18031 1
67 True False False spring 8 8.58384 46.33595 11.52974 2
68 True False False summer 3 6.34127 22.66891 19.15813 1
69 False True False spring 13 7.86448 8.85557 40.03913 3
70 True True False spring 13 8.89316 49.89548 21.04525 2
71 True True False autumn 9 0.91339 36.35922 16.09576 1
72 False False False summer 3 7.36268 28.50462 29.52973 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 3
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
80 False False True winter 1 8.32044 12.09058 37.28732 3
81 False True False spring 14 9.56618 48.49473 46.37651 2
82 True False True spring 10 9.33146 47.99213 35.92519 2
83 False True False spring 6 0.47396 37.45415 36.87019 1
84 True False False summer 12 7.61463 4.36339 36.07375 3
85 True True True autumn 3 6.42039 4.90383 43.29857 3
86 False True False winter 13 6.89007 43.09184 3.04284 2
87 True False True winter 1 6.56604 19.04681 27.58314 2
88 True False True spring 3 1.96784 2.18597 34.02966 1
89 False False False spring 0 3.76673 1.64674 34.50649 1
90 False False True summer 2 0.05382 10.48896 24.03557 1
91 True False True spring 14 5.12387 44.44585 8.35502 3
92 True True False autumn 10 4.90335 43.27857 27.22901 1
93 True False False winter 11 5.89082 28.91495 15.58095 1
94 True False True autumn 3 7.39589 21.53402 44.50694 3
95 True False False summer 12 5.68671 49.18777 22.53807 3
96 False False False winter 0 0.86765 41.28704 33.77284 1
97 False False True summer 10 5.97643 36.23669 48.32615 2
98 False True True autumn 7 1.76947 38.34692 13.28679 1
99 True True True summer 13 8.63622 16.14861 44.91355 3
100 True False False winter 11 8.48481 37.52722 47.76888 2
101 True True True summer 12 7.65812 4.16785 34.57922 3
102 False False True winter 7 8.44897 42.99815 44.66558 2
103 False False False winter 7 0.53067 13.47003 18.45329 1
104 False False False winter 14 3.24747 9.51144 6.62824 1
105 True True False spring 12 5.19071 47.53107 34.68942 2
106 True False False summer 9 6.9442 46.79146 13.92798 2
107 True False False autumn 1 3.09242 18.02023 11.03004 1
108 True True True spring 3 0.19271 1.00203 1.16671 1
109 False True True winter 5 9.00758 37.95091 11.54697 2
110 True False True spring 9 6.11904 37.42698 4.82627 2
111 False False True autumn 9 6.29507 22.99044 15.46992 2
112 False False False winter 13 5.4099 11.75134 6.91861 1
113 False False False winter 5 9.92035 21.82547 10.2415 2
114 False True False winter 10 6.06913 1.46795 12.76663 1
115 True False True spring 5 8.1218 37.03643 32.04156 3
116 True False False autumn 11 0.48844 39.36689 0.03464 1
117 False True True summer 6 1.72816 26.85829 16.53262 1
118 False False False spring 5 6.04025 29.55673 18.85232 2
119 False True True winter 2 1.75157 0.6601 49.91163 1
120 False True True winter 9 6.75125 15.22221 6.72688 2
121 False True True autumn 9 6.72535 24.07403 33.94074 2
122 False False False winter 14 0.02843 48.49973 15.81701 1
123 False False True autumn 15 1.07944 45.94025 4.05257 1
124 False False True winter 12 7.26288 15.82501 22.56163 2
125 True True True winter 11 8.50892 23.89966 46.14267 3
126 True False True autumn 11 8.10923 24.31448 6.70919 2
127 True True False summer 11 4.65313 3.44791 3.96313 3
128 True False True summer 2 2.56716 10.85536 49.88738 1
129 False False True autumn 4 8.19265 5.43942 48.74041 3
130 False True False autumn 5 5.6574 9.75738 25.96888 3
131 False True False winter 14 4.87066 33.40134 18.98246 2
132 True True True winter 6 8.2623 37.47298 33.76759 2
133 True True True spring 10 2.20409 13.6178 5.80078 2
134 True False True autumn 7 9.06057 37.8724 23.62209 2
135 False False True autumn 3 6.69861 37.07336 16.87187 2
136 True False True autumn 13 4.96475 46.87852 3.1412 1
137 True False True autumn 9 2.65212 19.06994 37.33364 1
138 True True False summer 15 3.47148 35.84529 0.00000 1
139 False True True summer 8 1.51025 9.44246 19.05913 1
140 False False True autumn 6 6.48485 45.61986 15.91179 2
141 False False False spring 2 8.98075 39.32941 42.47669 2
142 False True True winter 5 8.37177 12.99299 42.31566 3
143 True True True autumn 6 3.38746 48.86975 49.62605 1
144 False True True summer 7 7.09358 22.83074 38.5172 2
145 False False True spring 9 1.00148 11.16064 0.52706 1
146 False False True winter 1 6.08476 37.67744 4.49812 2
147 False True False spring 5 4.5182 32.48803 33.44274 1
148 True True True summer 8 6.11265 30.32015 46.47287 3
149 False True True winter 4 8.50937 22.72015 0.00000 2
150 True False True summer 4 7.23924 39.09963 42.82872 3
151 False False True summer 5 1.28353 7.18667 38.93923 1
152 False True False spring 3 4.50329 22.95269 0.41795 1
153 True True True summer 1 0.47824 14.79432 24.64273 1
154 False True False spring 10 8.43205 19.1333 20.95803 2
155 False True False spring 6 9.94659 18.83814 39.26147 2
156 False True False spring 3 3.68802 1.58951 26.4255 1
157 False False True autumn 8 4.79336 22.56564 4.95207 2
158 False True True spring 10 1.63541 0.00000 31.82704 1
159 False True False spring 2 1.2274 47.87731 32.98744 1
160 True True False winter 11 7.31457 26.08142 16.5835 2
161 False True True summer 2 4.90627 19.73976 49.56272 3
162 True True False winter 8 3.02707 35.9547 29.52088 1
163 True True True summer 7 5.02577 5.37674 16.61368 3
164 False False True spring 8 9.58805 8.12549 0.00000 2
165 False True True summer 6 2.08786 37.11126 36.15777 3
166 True True False spring 7 8.11839 12.2032 8.26737 2
167 True False True summer 7 4.08923 20.77025 11.25944 1
168 False False True winter 4 4.85557 0.00000 39.4493 2
169 False False False summer 14 9.12718 41.84025 49.51895 2
170 True True True summer 15 9.4014 34.10345 26.84361 3
171 False True False spring 14 8.61728 28.58017 39.3705 2
172 False True False winter 8 7.12808 12.04193 43.86622 2
173 True False True winter 1 9.50102 43.46168 28.81571 2
174 True True False spring 5 1.35366 6.95688 33.37058 1
175 False False True autumn 11 7.61014 11.10761 41.58039 2
176 False True True summer 2 6.86814 37.72905 14.64706 3
177 True False False winter 1 8.12812 22.55081 9.43532 2
178 True True True winter 10 4.18282 27.82423 30.42216 1
179 False False False summer 7 2.52646 3.74242 10.61286 1
180 False False True spring 13 3.15065 19.01632 34.56097 2
181 True True False summer 3 0.18108 46.67684 46.76693 1
182 True True True spring 0 1.50217 5.27541 16.18378 1
183 False True True summer 5 3.71758 11.15496 12.57224 3
184 False True False summer 6 9.92613 8.59078 21.32207 3
185 True False False winter 11 0.1261 2.42716 17.23296 1
186 True False True summer 14 6.90049 10.76539 3.92394 3
187 False True True autumn 15 1.76164 35.60051 2.5168 2
188 False False True spring 11 2.39225 36.14198 9.13906 3
189 True True False summer 2 4.04026 0.00000 12.47216 1
190 True True False spring 13 3.32803 7.59913 1.89442 3
191 True False True spring 1 5.15927 44.02139 4.03454 1
192 True True True autumn 13 5.52565 7.75133 38.62709 3
193 True True False spring 3 8.44216 30.01593 12.45777 3
194 False False True summer 13 2.88557 5.18905 5.87065 3
195 True True True spring 11 2.45261 7.22671 49.68806 3
196 True True True winter 4 8.55814 3.29899 32.82852 2
197 False False True summer 4 9.85169 47.62867 17.3155 3
198 False False True winter 2 5.30151 26.50068 48.79306 2
199 False False False autumn 9 7.59806 0.00000 36.92142 2
200 False True True autumn 1 9.28424 17.58014 28.42461 2
201 True False True summer 14 7.82306 35.29264 46.36975 3
202 False False True winter 2 1.10909 46.37088 40.88245 1
203 True True False summer 1 7.71442 43.2301 27.42849 3
204 False True True summer 6 1.21255 3.7357 4.31858 1
205 True True True winter 8 9.53076 12.54774 17.63524 2
206 True True True autumn 3 8.47955 19.04656 3.62988 2
207 True False True winter 3 2.58264 28.29242 0.00000 1
208 True False False autumn 5 6.83145 0.00000 15.88102 1
209 True False False summer 10 3.24742 16.50963 26.24036 1
210 False False False summer 8 8.66174 49.55046 33.2433 2
211 True False True winter 7 1.40722 4.06585 2.57929 1
212 False True False winter 12 4.483 2.42211 20.55941 2
213 False False True spring 12 2.98512 30.55243 5.53733 3
214 False False True autumn 6 0.84086 33.57311 32.42908 1
215 False True True winter 12 1.07916 8.27438 7.9284 1
216 False False True spring 12 3.17402 46.59657 14.21739 3
217 False True True winter 11 7.09559 14.18261 43.41709 2
218 False False True autumn 3 0.53006 21.37664 17.14295 1
219 False False False autumn 14 4.67143 4.11788 0.04226 1
220 True False True winter 12 3.48493 35.24303 0.00000 1
221 True True True spring 9 5.1789 0.97673 8.31413 2
222 False False False spring 5 1.50319 28.57762 27.80054 1
223 True True True autumn 10 9.23444 43.51842 19.90954 2
224 False False False autumn 9 3.84582 40.34953 9.01663 1
225 True True False winter 5 3.90587 32.97826 0.67046 1
226 True True True autumn 2 9.19994 0.00000 34.36662 3
227 False True True summer 6 5.614 29.08038 0.00000 2
228 True True True autumn 2 2.15339 6.36751 6.45082 1
229 True False True spring 1 9.19416 32.05433 8.27667 2
230 True False True autumn 0 8.12282 48.68677 8.38304 2
231 False True True spring 12 3.26729 29.61584 1.69993 2
232 True False True summer 8 1.99886 31.26437 3.51834 1
233 False False True summer 7 7.41314 44.88982 34.46453 2
234 True False True summer 0 7.24464 8.85289 34.29828 3
235 False True False summer 8 2.38628 21.76861 47.20283 3
236 True True True autumn 3 7.12112 12.08359 41.06062 3
237 True False False winter 5 6.74504 47.09367 1.97357 2
238 False False False summer 8 1.23539 35.47945 7.67276 1
239 True False False spring 11 7.91742 34.52557 30.96412 3
240 False True True winter 14 5.91181 7.53226 16.37669 3
241 False True True spring 13 6.07261 47.43572 15.83885 2
242 True True True autumn 2 9.22518 31.25996 28.06488 3
243 False True True summer 3 8.47609 0.23934 31.25786 3
244 False True False autumn 6 0.97126 13.65648 25.59887 1
245 True False False spring 14 9.29029 46.83676 12.58912 2
246 False False False winter 14 0.14092 4.6673 20.3859 1
247 True False True autumn 2 3.52708 37.61372 32.83573 1
248 True True True winter 1 4.37134 43.19138 22.04785 1
249 True False True summer 9 1.1614 10.9739 42.3009 1
250 False False False winter 9 7.27324 29.74731 47.17759 2
251 False True True winter 9 3.17153 35.14715 21.37868 2
252 False True False autumn 0 2.37863 20.35733 46.96943 1
253 False False True autumn 4 0.70656 8.70201 5.26527 1
254 True True True winter 1 8.23562 36.01552 25.03969 2
255 True True False winter 3 6.65062 6.75622 24.91086 3
256 False False False spring 10 2.30179 19.62758 25.57147 1
257 True True False autumn 10 6.60812 6.61336 12.39931 3
258 False False True summer 3 8.9948 47.39225 18.11157 2
259 True False True autumn 5 6.69302 42.62701 13.01677 2
260 False False False spring 14 8.53868 33.42545 2.43572 2
261 False True True autumn 10 4.46205 10.37542 39.58137 3
262 True True False spring 14 5.34262 15.45545 21.48404 3
263 True False False winter 9 7.02885 4.88308 27.56619 3
264 False False False autumn 13 3.55279 0.17091 5.43831 1
265 True True True autumn 1 9.98637 27.57982 15.82173 2
266 False True True summer 9 8.25408 13.10493 27.07596 3
267 False False False spring 15 1.9089 33.25115 44.57492 1
268 True False False autumn 12 6.65534 38.00972 20.31047 2
269 False True True autumn 1 0.01592 6.24929 15.51308 1
270 False True True winter 13 1.24017 36.88006 16.50894 1
271 False True True winter 13 6.1878 15.18876 9.02381 2
272 True True True winter 5 5.45157 13.27868 39.39805 2
273 True False True spring 5 2.82881 28.62319 24.03077 1
274 False False True spring 2 4.8246 41.45269 48.89539 2
275 True False False spring 8 9.3343 39.02018 45.01066 3
276 True True True autumn 4 1.8456 2.94366 37.44996 1
277 False True True summer 14 0.95333 4.57964 26.37633 1
278 False False True autumn 13 9.84087 24.03819 41.72097 2
279 True False False autumn 9 3.70617 32.70115 1.69105 1
280 True True True spring 12 6.77783 6.67976 20.46179 3
281 False False True summer 15 7.15829 31.24546 10.37666 3
282 False True True summer 1 2.28393 18.13299 34.38756 3
283 True False True autumn 7 3.96302 39.84093 47.0172 1
284 True False False summer 1 0.65085 20.20581 14.96995 1
285 True False False winter 2 9.24331 26.34543 30.5147 2
286 True False False summer 3 2.86309 15.56342 1.04324 1
287 True False False summer 1 4.03947 33.84073 6.48891 1
288 True False False winter 4 2.46471 24.07929 17.77792 1
289 False False False winter 9 3.66415 23.68306 24.43865 1
290 True True True autumn 8 5.71809 24.41045 48.78273 2
291 False True True spring 3 5.3009 34.83862 6.75862 2
292 True False True winter 8 6.23275 8.1183 19.6922 3
293 False True True autumn 2 4.21016 11.24334 34.98395 3
294 True True False autumn 0 2.79424 13.25106 5.69617 1
295 True True False winter 15 2.43843 14.61703 49.57393 2
296 True True True summer 8 2.28654 20.9895 5.64007 1
297 False False False autumn 1 2.5607 26.85209 47.10784 1
298 True True True winter 14 1.56638 18.02703 7.05011 1
299 False False False winter 13 3.86632 28.9884 20.1928 1
300 True False False summer 13 6.37654 34.3833 34.53892 3
301 True True False summer 5 8.10422 7.6617 23.41017 3

49
decision_tree.py Normal file
View File

@ -0,0 +1,49 @@
import pandas as pd
from sklearn.tree import DecisionTreeClassifier, plot_tree, export_graphviz
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
headers = ['adult','active_time','ill','season','guests','hunger','wet_food','dry_food']
# Wczytanie danych
data = pd.read_csv('dane.csv', header=0)
X = data[['adult','active_time','ill','season','guests','hunger','wet_food','dry_food']]
Y = data['decision']
X = pd.get_dummies(data=X, columns=['season'])
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, train_size=0.8)
clf = DecisionTreeClassifier(random_state=0, min_samples_leaf = 4, min_samples_split=2)
clf = clf.fit(X_train, Y_train)
Y_pred = clf.predict(X_test)
accuracy = accuracy_score(Y_test, Y_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ą']) # filled=True koloruje węzły
plt.savefig('tree.png')
# Nowe dane
def add_data(adult,active_time,ill,season,guests,hunger,wet_food,dry_food):
X_new = pd.DataFrame({
'adult': [adult],
'active_time': [active_time],
'ill': [ill],
'season': [season],
'guests':[guests],
'hunger': [hunger],
'wet_food': [wet_food],
'dry_food': [dry_food]
})
X_new_encoded = pd.get_dummies(X_new)
missing_columns = set(X.columns) - set(X_new.columns)
for col in missing_columns:
X_new_encoded[col] = 0
X_new_encoded = X_new_encoded.reindex(columns=X.columns, fill_value=0)
print("Atrybuty zwierzęcia:", adult,active_time,ill,season,guests,hunger,wet_food,dry_food)
return (clf.predict(X_new_encoded))

View File

@ -3,7 +3,7 @@ import pygame
import sys
sys.path.append('./Animals')
from decision_tree import add_data
from animals import create_animals, draw_Animals
from agent import Agent
from enclosure import create_enclosures, draw_enclosures, draw_gates
@ -84,7 +84,7 @@ def main():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
agent.handle_event(event, const.GRID_WIDTH, const.GRID_HEIGHT, Animals, obstacles)
agent.handle_event(event, const.GRID_WIDTH, const.GRID_HEIGHT, Animals, obstacles,const)
change_time(const)
draw_background(const)
@ -93,6 +93,7 @@ def main():
draw_gates(Enclosures, const)
draw_house(const)
if not spawned:
spawn_all_animals()
@ -110,10 +111,10 @@ def main():
if actions:
action = actions.pop(0)
agent.move(action, const.GRID_WIDTH, const.GRID_HEIGHT, obstacles, Animals, goal)
agent.move(action, const.GRID_WIDTH, const.GRID_HEIGHT, obstacles, Animals, goal,const)
pygame.time.wait(200)
else:
if agent._food != 0:
if agent._dryfood != 0 or agent._wetfood != 0 :
animal = random.choice(Animals)
goal = (animal.x, animal.y)
draw_goal(const, goal)

BIN
tree.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 KiB