Merge pull request 'Algorytm_genetyczny' (#3) from Algorytm_genetyczny into master
Reviewed-on: s481865/Male_zoo#3
This commit is contained in:
commit
b53ec67fa3
@ -3,5 +3,5 @@
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.9" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (pythonProject)" project-jdk-type="Python SDK" />
|
||||
</project>
|
@ -1,8 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (pythonProject)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,17 +1,31 @@
|
||||
import random
|
||||
import pygame
|
||||
from abc import abstractmethod
|
||||
|
||||
class Animal:
|
||||
def __init__(self, x, y,name, image, food_image, food, environment, adult=False,):
|
||||
|
||||
def choose_picture(self, name):
|
||||
ran = random.randint(0, 1)
|
||||
if ran == 0:
|
||||
path = f'images/{name}.png'
|
||||
return path
|
||||
else:
|
||||
path = f'images/{name}2.png'
|
||||
return path
|
||||
|
||||
def __init__(self, x, y,name, image_path, food_image, food, environment, activity, ill=False, adult=False,):
|
||||
self.x = x - 1
|
||||
self.y = y - 1
|
||||
self.name = name
|
||||
self.image = image
|
||||
self.image_path = image_path
|
||||
self.image = pygame.image.load(image_path)
|
||||
self.adult = adult
|
||||
self.food = food
|
||||
self.food_image = food_image
|
||||
self._feed = 0
|
||||
self.environment = environment #hot/cold/medium
|
||||
self.environment = environment # hot/cold/medium
|
||||
self.activity = activity # diurnal/nocturnal
|
||||
self.ill = ill
|
||||
|
||||
def draw(self, screen, grid_size):
|
||||
if self.adult:
|
||||
@ -30,9 +44,9 @@ class Animal:
|
||||
exclamation_image = pygame.transform.scale(exclamation_image, (int(grid_size * 0.45), int(grid_size * 0.45)))
|
||||
screen.blit(exclamation_image, (x * grid_size, y * grid_size))
|
||||
|
||||
def draw_food(self, screen, grid_size, x, y):
|
||||
def draw_food(self, screen, grid_size, x, y,food_image):
|
||||
scale = 0.45
|
||||
food_image = pygame.image.load(self.food_image)
|
||||
food_image = pygame.image.load(food_image)
|
||||
|
||||
if(self.adult):
|
||||
y = y + 1
|
||||
@ -40,9 +54,32 @@ class Animal:
|
||||
food_image = pygame.transform.scale(food_image, (int(grid_size * scale), int(grid_size * scale)))
|
||||
screen.blit(food_image, (x * grid_size, (y + 1) * grid_size - int(grid_size * scale)))
|
||||
|
||||
@abstractmethod
|
||||
def feed(self):
|
||||
pass
|
||||
def is_ill(self):
|
||||
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
|
||||
illness_image = pygame.image.load('images/ill.png')
|
||||
y = y
|
||||
|
||||
if self.adult:
|
||||
x = x + 1
|
||||
y = y
|
||||
scale = 0.7
|
||||
|
||||
x_blit = x * grid_size + (grid_size - int(grid_size * scale))
|
||||
illness_image = pygame.transform.scale(illness_image, (int(grid_size * scale), int(grid_size * scale)))
|
||||
screen.blit(illness_image, (x_blit, y * grid_size))
|
||||
|
||||
def draw_snack(self, screen, grid_size, x, y):
|
||||
exclamation_image = pygame.image.load(self.food_image)
|
||||
exclamation_image = pygame.transform.scale(exclamation_image, (int(grid_size * 0.45), int(grid_size * 0.45)))
|
||||
screen.blit(exclamation_image, (x * grid_size, y * grid_size))
|
||||
pygame.display.update()
|
||||
pygame.time.wait(700)
|
||||
|
||||
@abstractmethod
|
||||
def getting_hungry(self):
|
||||
|
@ -3,6 +3,8 @@ from giraffe import Giraffe
|
||||
from penguin import Penguin
|
||||
from parrot import Parrot
|
||||
from bear import Bear
|
||||
from owl import Owl
|
||||
from bat import Bat
|
||||
|
||||
def create_animals():
|
||||
giraffe1 = Giraffe(0, 0, adult=True)
|
||||
@ -26,22 +28,35 @@ def create_animals():
|
||||
elephant5 = Elephant(0, 0)
|
||||
parrot1 = Parrot(0, 0)
|
||||
parrot2 = Parrot(0, 0)
|
||||
parrot3 = Parrot(0, 0)
|
||||
parrot4 = Parrot(0, 0)
|
||||
parrot5 = Parrot(0, 0)
|
||||
owl1 = Owl(0, 0)
|
||||
owl2 = Owl(0, 0)
|
||||
bat1 = Bat(0, 0)
|
||||
bat2 = Bat(0, 0)
|
||||
|
||||
Animals = [giraffe1, giraffe2, giraffe3, giraffe4, giraffe5,
|
||||
bear1, bear2, bear3, bear4, bear5,
|
||||
elephant1, elephant2, elephant3, elephant4, elephant5,
|
||||
penguin1, penguin2, penguin3, penguin4,
|
||||
parrot1, parrot2, parrot3, parrot4, parrot5]
|
||||
parrot1, parrot2, owl1, owl2, bat1, bat2]
|
||||
|
||||
return Animals
|
||||
|
||||
def draw_Animals(Animals, const):
|
||||
for Animal in Animals:
|
||||
Animal.draw(const.screen, const.GRID_SIZE)
|
||||
if Animal.feed() == 'True':
|
||||
Animal.draw_exclamation(const.screen, const.GRID_SIZE, Animal.x, Animal.y)
|
||||
else:
|
||||
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y)
|
||||
|
||||
hunger_level = Animal.getting_hungry(const)
|
||||
|
||||
if hunger_level >= 9:
|
||||
food_image = 'images/empty_bowl.png'
|
||||
elif hunger_level >= 8:
|
||||
food_image = 'images/almost_empty.png'
|
||||
elif hunger_level >= 5:
|
||||
food_image = 'images/half_bowl.png'
|
||||
else:
|
||||
food_image = 'images/full_bowl.png'
|
||||
|
||||
Animal.draw_food(const.screen, const.GRID_SIZE, Animal.x, Animal.y, food_image)
|
||||
|
||||
if Animal.ill:
|
||||
Animal.draw_illness(const.screen, const.GRID_SIZE, Animal.x, Animal.y)
|
26
Animals/bat.py
Normal file
26
Animals/bat.py
Normal file
@ -0,0 +1,26 @@
|
||||
from animal import Animal
|
||||
import pygame
|
||||
from datetime import datetime
|
||||
|
||||
class Bat(Animal):
|
||||
def __init__(self, x, y, adult=False):
|
||||
name = 'bat'
|
||||
image_path = self.choose_picture(name)
|
||||
environment = "medium"
|
||||
food_image = 'images/grains.png'
|
||||
parrot_food = 'grains'
|
||||
activity = 'nocturnal'
|
||||
super().__init__(x, y,name, image_path, food_image,parrot_food, environment, adult)
|
||||
self._starttime = datetime.now()
|
||||
|
||||
def getting_hungry(self, const):
|
||||
checktime = datetime.now()
|
||||
delta = checktime - self._starttime
|
||||
minutes_passed = delta.total_seconds() / (25)
|
||||
self._starttime = checktime
|
||||
|
||||
if const.IS_NIGHT and self._feed < 10:
|
||||
self._feed += minutes_passed
|
||||
self._feed = min(self._feed, 10)
|
||||
|
||||
return self._feed
|
@ -4,27 +4,24 @@ from datetime import datetime
|
||||
|
||||
class Bear(Animal):
|
||||
def __init__(self, x, y, adult=False):
|
||||
Bear_image = pygame.image.load('images/bear.png')
|
||||
name = 'bear'
|
||||
image_path = self.choose_picture(name)
|
||||
environment = "cold"
|
||||
activity = 'nocturnal'
|
||||
ill = self.is_ill()
|
||||
bear_food = 'meat'
|
||||
food_image = 'images/meat.png'
|
||||
super().__init__(x, y,name, Bear_image, food_image,bear_food,environment, adult)
|
||||
super().__init__(x, y,name, image_path, food_image,bear_food,environment, activity, ill, adult)
|
||||
self._starttime = datetime.now()
|
||||
|
||||
|
||||
|
||||
def feed(self):
|
||||
self.getting_hungry()
|
||||
if self._feed < 2:
|
||||
return 'False'
|
||||
else:
|
||||
return 'True'
|
||||
def getting_hungry(self, const):
|
||||
|
||||
|
||||
def getting_hungry(self):
|
||||
checktime = datetime.now()
|
||||
delta = checktime - self._starttime
|
||||
minutes_passed = delta.total_seconds() / 60
|
||||
self._feed += minutes_passed
|
||||
self._starttime = checktime
|
||||
minutes_passed = delta.total_seconds() / (45)
|
||||
self._starttime = checktime
|
||||
|
||||
if const.IS_NIGHT and self._feed < 10 and const.season != "winter":
|
||||
self._feed += minutes_passed
|
||||
self._feed = min(self._feed, 10)
|
||||
return self._feed
|
@ -2,13 +2,13 @@ from animal import Animal
|
||||
import pygame
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
||||
class Elephant(Animal):
|
||||
def __init__(self, x, y, adult=False):
|
||||
Elephant_image = pygame.image.load('images/elephant.png')
|
||||
name = 'elephant'
|
||||
image_path = self.choose_picture(name)
|
||||
environment = "hot"
|
||||
activity = 'diurnal'
|
||||
ill = self.is_ill()
|
||||
if adult:
|
||||
elephant_food = 'leavs'
|
||||
food_image = 'images/leaves.png'
|
||||
@ -16,22 +16,16 @@ class Elephant(Animal):
|
||||
elephant_food = 'milk'
|
||||
food_image = 'images/milk.png'
|
||||
|
||||
super().__init__(x, y,name, Elephant_image, food_image,elephant_food, environment, adult)
|
||||
super().__init__(x, y,name, image_path, food_image,elephant_food, environment, activity, ill, adult)
|
||||
self._starttime = datetime.now()
|
||||
|
||||
|
||||
|
||||
def feed(self):
|
||||
self.getting_hungry()
|
||||
if self._feed < 0.3:
|
||||
return 'False'
|
||||
else:
|
||||
return 'True'
|
||||
|
||||
|
||||
def getting_hungry(self):
|
||||
|
||||
def getting_hungry(self, const):
|
||||
checktime = datetime.now()
|
||||
delta = checktime - self._starttime
|
||||
minutes_passed = delta.total_seconds() / 60
|
||||
self._feed += minutes_passed
|
||||
self._starttime = checktime
|
||||
minutes_passed = delta.total_seconds() / (90)
|
||||
self._starttime = checktime
|
||||
|
||||
if not const.IS_NIGHT and self._feed < 10:
|
||||
self._feed += minutes_passed
|
||||
self._feed = min(self._feed, 10)
|
||||
return self._feed
|
@ -2,31 +2,25 @@ from animal import Animal
|
||||
import pygame
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
||||
class Giraffe(Animal):
|
||||
def __init__(self, x, y, adult=False):
|
||||
Giraffe_image = pygame.image.load('images/giraffe.png')
|
||||
name = 'giraffe'
|
||||
image_path = self.choose_picture(name)
|
||||
environment = "hot"
|
||||
activity = 'diurnal'
|
||||
ill = self.is_ill()
|
||||
food_image = 'images/leaves.png'
|
||||
giraffe_food = 'leaves'
|
||||
super().__init__(x, y,name, Giraffe_image, food_image,giraffe_food, environment, adult)
|
||||
super().__init__(x, y, name, image_path, food_image,giraffe_food, environment, activity, ill, adult)
|
||||
self._starttime = datetime.now()
|
||||
|
||||
|
||||
|
||||
def feed(self):
|
||||
self.getting_hungry()
|
||||
if self._feed < 0.8:
|
||||
return 'False'
|
||||
else:
|
||||
return 'True'
|
||||
|
||||
|
||||
def getting_hungry(self):
|
||||
def getting_hungry(self, const):
|
||||
checktime = datetime.now()
|
||||
delta = checktime - self._starttime
|
||||
minutes_passed = delta.total_seconds() / 60
|
||||
self._feed += minutes_passed
|
||||
self._starttime = checktime
|
||||
minutes_passed = delta.total_seconds() / (60)
|
||||
self._starttime = checktime
|
||||
|
||||
if not const.IS_NIGHT and self._feed < 10:
|
||||
self._feed += minutes_passed
|
||||
self._feed = min(self._feed, 10)
|
||||
return self._feed
|
26
Animals/owl.py
Normal file
26
Animals/owl.py
Normal file
@ -0,0 +1,26 @@
|
||||
from animal import Animal
|
||||
import pygame
|
||||
from datetime import datetime
|
||||
|
||||
class Owl(Animal):
|
||||
def __init__(self, x, y, adult=False):
|
||||
name = 'owl'
|
||||
image_path = self.choose_picture(name)
|
||||
environment = "medium"
|
||||
food_image = 'images/grains.png'
|
||||
parrot_food = 'grains'
|
||||
activity = 'nocturnal'
|
||||
super().__init__(x, y,name, image_path, food_image,parrot_food, environment, adult)
|
||||
self._starttime = datetime.now()
|
||||
|
||||
def getting_hungry(self, const):
|
||||
checktime = datetime.now()
|
||||
delta = checktime - self._starttime
|
||||
minutes_passed = delta.total_seconds() / (50)
|
||||
self._starttime = checktime
|
||||
|
||||
if const.IS_NIGHT and self._feed < 10:
|
||||
self._feed += minutes_passed
|
||||
self._feed = min(self._feed, 10)
|
||||
|
||||
return self._feed
|
@ -2,31 +2,25 @@ from animal import Animal
|
||||
import pygame
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
||||
class Parrot(Animal):
|
||||
def __init__(self, x, y, adult=False):
|
||||
Parrot_image = pygame.image.load('images/parrot.png')
|
||||
name = 'parrot'
|
||||
image_path = self.choose_picture(name)
|
||||
environment = "medium"
|
||||
activity = 'diurnal'
|
||||
ill = self.is_ill()
|
||||
food_image = 'images/grains.png'
|
||||
parrot_food = 'grains'
|
||||
super().__init__(x, y,name, Parrot_image, food_image,parrot_food, environment, adult)
|
||||
super().__init__(x, y, name, image_path, food_image, parrot_food, environment, activity, ill, adult)
|
||||
self._starttime = datetime.now()
|
||||
|
||||
|
||||
|
||||
def feed(self):
|
||||
self.getting_hungry()
|
||||
if self._feed < 1.5:
|
||||
return 'False'
|
||||
else:
|
||||
return 'True'
|
||||
|
||||
|
||||
def getting_hungry(self):
|
||||
def getting_hungry(self, const):
|
||||
checktime = datetime.now()
|
||||
delta = checktime - self._starttime
|
||||
minutes_passed = delta.total_seconds() / 60
|
||||
self._feed += minutes_passed
|
||||
self._starttime = checktime
|
||||
minutes_passed = delta.total_seconds() / (30)
|
||||
self._starttime = checktime
|
||||
|
||||
if not const.IS_NIGHT and self._feed < 10:
|
||||
self._feed += minutes_passed
|
||||
self._feed = min(self._feed, 10)
|
||||
return self._feed
|
@ -2,31 +2,25 @@ from animal import Animal
|
||||
import pygame
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
||||
class Penguin(Animal):
|
||||
def __init__(self, x, y, adult=False):
|
||||
Penguin_image = pygame.image.load('images/penguin.png')
|
||||
name = 'penguin'
|
||||
image_path = self.choose_picture(name)
|
||||
environment = "cold"
|
||||
activity = 'diurnal'
|
||||
ill = self.is_ill()
|
||||
food_image = 'images/fish.png'
|
||||
penguin_food = 'fish'
|
||||
super().__init__(x, y,name, Penguin_image, food_image,penguin_food,environment, adult)
|
||||
super().__init__(x, y, name, image_path, food_image, penguin_food, environment, activity, ill, adult)
|
||||
self._starttime = datetime.now()
|
||||
|
||||
|
||||
|
||||
def feed(self):
|
||||
self.getting_hungry()
|
||||
if self._feed < 2:
|
||||
return 'False'
|
||||
else:
|
||||
return 'True'
|
||||
|
||||
|
||||
def getting_hungry(self):
|
||||
def getting_hungry(self, const):
|
||||
checktime = datetime.now()
|
||||
delta = checktime - self._starttime
|
||||
minutes_passed = delta.total_seconds() / 60
|
||||
self._feed += minutes_passed
|
||||
self._starttime = checktime
|
||||
minutes_passed = delta.total_seconds() / (25)
|
||||
self._starttime = checktime
|
||||
|
||||
if not const.IS_NIGHT and self._feed < 10:
|
||||
self._feed += minutes_passed
|
||||
self._feed = min(self._feed, 10)
|
||||
return self._feed
|
88
agent.py
88
agent.py
@ -1,6 +1,23 @@
|
||||
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 feed_decision
|
||||
from constants import Constants
|
||||
from classification import AnimalClassifier
|
||||
|
||||
const = Constants()
|
||||
|
||||
classes = [
|
||||
"bat",
|
||||
"bear",
|
||||
"elephant",
|
||||
"giraffe",
|
||||
"owl",
|
||||
"parrot",
|
||||
"penguin"
|
||||
]
|
||||
class Agent:
|
||||
def __init__(self, istate, image_path, grid_size):
|
||||
self.istate = istate
|
||||
@ -8,8 +25,10 @@ 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._dryfood = 0
|
||||
self._wetfood = 0
|
||||
|
||||
def draw(self, screen, grid_size):
|
||||
def draw(self, const):
|
||||
# Obróć obrazek zgodnie z kierunkiem
|
||||
if self.direction == 'E':
|
||||
self.image= pygame.image.load('images/agent4.png')
|
||||
@ -19,19 +38,21 @@ class Agent:
|
||||
self.image= pygame.image.load('images/agent3.png')
|
||||
else: # direction == 'N'
|
||||
self.image= pygame.image.load('images/agent2.png')
|
||||
self.image = pygame.transform.scale(self.image, (grid_size, grid_size))
|
||||
screen.blit(self.image, (self.x * self.grid_size, self.y * self.grid_size))
|
||||
self.image = pygame.transform.scale(self.image, (const.GRID_SIZE, const.GRID_SIZE))
|
||||
const.screen.blit(self.image, (self.x * self.grid_size, self.y * self.grid_size))
|
||||
|
||||
def handle_event(self, event, max_x, max_y, animals, obstacles):
|
||||
if const.IS_NIGHT: draw_night(const)
|
||||
|
||||
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':
|
||||
@ -54,13 +75,54 @@ 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
|
||||
neuron = AnimalClassifier('./model/best_model.pth', classes)
|
||||
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.feed() == 'True':
|
||||
animal._feed = 0
|
||||
print(animal.name, "fed with", animal.food)
|
||||
if (animal.activity == 'nocturnal' and const.IS_NIGHT) or (animal.activity == 'diurnal' and not(const.IS_NIGHT)):
|
||||
activity_time = True
|
||||
else:
|
||||
activity_time = False
|
||||
guests = random.randint(1, 15)
|
||||
guess = neuron.classify(animal.image_path)
|
||||
if guess == animal.name:
|
||||
print(f"I'm sure this is {guess} and i give it {animal.food} as a snack")
|
||||
animal.draw_snack(const.screen, const.GRID_SIZE, animal.x, animal.y)
|
||||
else:
|
||||
print(f"I was wrong, this is not a {guess} but a {animal.name}")
|
||||
decision = feed_decision(animal.adult, activity_time, animal.ill, const.season, guests, animal._feed, self._dryfood, self._wetfood)
|
||||
if decision != [1]:
|
||||
if decision == [2]:
|
||||
if animal.getting_hungry(const=Constants()) < self._wetfood :
|
||||
self._wetfood -= animal._feed
|
||||
animal._feed = 0
|
||||
else:
|
||||
animal._feed -= self._wetfood
|
||||
self._wetfood = 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._dryfood < 1 or self._wetfood < 1:
|
||||
self._dryfood = 50
|
||||
self._wetfood = 50
|
||||
print("Agent took food and current food level is", self._dryfood, self._wetfood)
|
||||
|
47
classification.py
Normal file
47
classification.py
Normal file
@ -0,0 +1,47 @@
|
||||
import torch
|
||||
import torchvision.transforms as transforms
|
||||
import PIL.Image as Image
|
||||
|
||||
class AnimalClassifier:
|
||||
def __init__(self, model_path, classes, image_size=224, mean=None, std=None):
|
||||
self.classes = classes
|
||||
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
||||
self.model = torch.load(model_path, map_location=torch.device('cpu'))
|
||||
self.model = self.model.to(self.device)
|
||||
self.model = self.model.eval()
|
||||
self.image_size = image_size
|
||||
self.mean = mean if mean is not None else [0.5164, 0.5147, 0.4746]
|
||||
self.std = std if std is not None else [0.2180, 0.2126, 0.2172]
|
||||
self.image_transforms = transforms.Compose([
|
||||
transforms.Resize((self.image_size, self.image_size)),
|
||||
transforms.ToTensor(),
|
||||
transforms.Normalize(torch.Tensor(self.mean), torch.Tensor(self.std))
|
||||
])
|
||||
|
||||
def classify(self, image_path):
|
||||
image = Image.open(image_path)
|
||||
|
||||
if image.mode == 'RGBA':
|
||||
image = image.convert('RGB')
|
||||
|
||||
image = self.image_transforms(image).float()
|
||||
image = image.unsqueeze(0).to(self.device)
|
||||
|
||||
with torch.no_grad():
|
||||
output = self.model(image)
|
||||
|
||||
_, predicted = torch.max(output.data, 1)
|
||||
|
||||
return self.classes[predicted.item()]
|
||||
|
||||
classes = [
|
||||
"bat",
|
||||
"bear",
|
||||
"elephant",
|
||||
"giraffe",
|
||||
"owl",
|
||||
"parrot",
|
||||
"penguin"
|
||||
]
|
||||
|
||||
|
13
constants.py
13
constants.py
@ -1,15 +1,26 @@
|
||||
import random
|
||||
import pygame
|
||||
import time
|
||||
|
||||
class Constants:
|
||||
def __init__(self):
|
||||
self.BLACK = (0, 0, 0)
|
||||
self.RED = (255, 0, 0)
|
||||
self.GRID_SIZE = 50
|
||||
self.GRID_SIZE = 65
|
||||
self.GRID_WIDTH = 30
|
||||
self.GRID_HEIGHT = 15
|
||||
self.WINDOW_SIZE = (self.GRID_WIDTH * self.GRID_SIZE, self.GRID_HEIGHT * self.GRID_SIZE)
|
||||
self.background_image = pygame.transform.scale(pygame.image.load('images/tło.jpg'), self.WINDOW_SIZE)
|
||||
|
||||
self.IS_NIGHT = False
|
||||
self.TIME_CHANGE = time.time() + 60
|
||||
|
||||
self.season = random.choice(["spring", "summer", "autumn", "winter"])
|
||||
|
||||
self.SIZE = 224
|
||||
self.mean = [0.5164, 0.5147, 0.4746]
|
||||
self.std = [0.2180, 0.2126, 0.2172]
|
||||
|
||||
def init_pygame(const):
|
||||
pygame.init()
|
||||
const.screen = pygame.display.set_mode(const.WINDOW_SIZE)
|
313
dane.csv
Normal file
313
dane.csv
Normal file
@ -0,0 +1,313 @@
|
||||
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,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
|
||||
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,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
|
||||
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,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
|
||||
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,True,autumn,3,7.39589,21.53402,0.00000,2
|
||||
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,autumn,5,5.6574,9.75738,0.00000,2
|
||||
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
|
||||
False,False,True,autumn,3,6.69861,0.00000,16.87187,3
|
||||
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,True,True,autumn,8,5.71809,24.41045,48.78273,2
|
||||
True,True,True,autumn,8,5.71809,24.41045,48.78273,2
|
||||
True,True,True,winter,8,5.71809,0.99999,48.78273,3
|
||||
True,True,True,winter,8,5.71809,1.98675,48.79993,3
|
||||
True,True,False,winter,8,7.71809,1.02345,38.78273,3
|
||||
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,False,False,summer,13,6.37654,34.3833,34.53892,3
|
||||
True,False,False,spring,11,8.35634,0.00000,34.53892,3
|
||||
True,False,True,summer,13,9.37654,34.3833,0.00000,2
|
||||
True,False,False,winter,13,7.77754,34.3833,0.00000,2
|
||||
True,True,True,summer,5,8.10422,7.6617,23.41017,3
|
|
48
decision_tree.py
Normal file
48
decision_tree.py
Normal file
@ -0,0 +1,48 @@
|
||||
import pandas as pd
|
||||
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
|
||||
headers = ['adult','active_time','ill','season','guests','hunger','wet_food','dry_food']
|
||||
# Wczytanie danych
|
||||
data = pd.read_csv('dane.csv', header=0)
|
||||
X = data[headers]
|
||||
Y = data['d |