Marta miniprojekt + raport
This commit is contained in:
parent
27a5abb035
commit
ecd41469ec
@ -1,8 +1,11 @@
|
||||
<?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$/Restaurant/Marta/venv" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.7 (Restaurant)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (Restaurant)" project-jdk-type="Python SDK" />
|
||||
</project>
|
11
Restaurant/Marta/.idea/Marta.iml
Normal file
11
Restaurant/Marta/.idea/Marta.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.7 (Restaurant)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TestRunnerService">
|
||||
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
|
||||
</component>
|
||||
</module>
|
4
Restaurant/Marta/.idea/encodings.xml
Normal file
4
Restaurant/Marta/.idea/encodings.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||
</project>
|
4
Restaurant/Marta/.idea/misc.xml
Normal file
4
Restaurant/Marta/.idea/misc.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (Restaurant)" project-jdk-type="Python SDK" />
|
||||
</project>
|
8
Restaurant/Marta/.idea/modules.xml
Normal file
8
Restaurant/Marta/.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Marta.iml" filepath="$PROJECT_DIR$/.idea/Marta.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
Restaurant/Marta/.idea/vcs.xml
Normal file
6
Restaurant/Marta/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
172
Restaurant/Marta/.idea/workspace.xml
Normal file
172
Restaurant/Marta/.idea/workspace.xml
Normal file
@ -0,0 +1,172 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="4e2e329c-455e-42fa-af0e-b9c332516a0c" name="Default Changelist" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/Marta.iml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/DecisionTreeGenerate.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../../.idea/DSZI.iml" beforeDir="false" afterPath="$PROJECT_DIR$/../../.idea/DSZI.iml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../../.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../.idea/misc.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../main.py" beforeDir="false" afterPath="$PROJECT_DIR$/../main.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileEditorManager">
|
||||
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/DecisionTreeGenerate.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="529">
|
||||
<caret line="76" column="51" selection-start-line="76" selection-start-column="51" selection-end-line="76" selection-end-column="51" />
|
||||
<folding>
|
||||
<element signature="e#0#19#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
</leaf>
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Python Script" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." />
|
||||
</component>
|
||||
<component name="IdeDocumentHistory">
|
||||
<option name="CHANGED_PATHS">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/DecisionTreeGenerate.py" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds" extendedState="6">
|
||||
<option name="x" value="-8" />
|
||||
<option name="y" value="-8" />
|
||||
<option name="width" value="1382" />
|
||||
<option name="height" value="744" />
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||
<component name="ProjectView">
|
||||
<navigator proportions="" version="1">
|
||||
<foldersAlwaysOnTop value="true" />
|
||||
</navigator>
|
||||
<panes>
|
||||
<pane id="Scope" />
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<expand>
|
||||
<path>
|
||||
<item name="Marta" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="Marta" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
|
||||
</component>
|
||||
<component name="RunDashboard">
|
||||
<option name="ruleStates">
|
||||
<list>
|
||||
<RuleState>
|
||||
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
<RuleState>
|
||||
<option name="name" value="StatusDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="DecisionTreeGenerate" type="PythonConfigurationType" factoryName="Python" temporary="true">
|
||||
<module name="Marta" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/DecisionTreeGenerate.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Python.DecisionTreeGenerate" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="4e2e329c-455e-42fa-af0e-b9c332516a0c" name="Default Changelist" comment="" />
|
||||
<created>1588865650965</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1588865650965</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="-8" y="-8" width="1382" height="744" extended-state="7" />
|
||||
<layout>
|
||||
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25" />
|
||||
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
|
||||
<window_info id="Favorites" order="2" side_tool="true" />
|
||||
<window_info anchor="bottom" id="Message" order="0" />
|
||||
<window_info anchor="bottom" id="Find" order="1" />
|
||||
<window_info anchor="bottom" id="Run" order="2" weight="0.3289689" />
|
||||
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
|
||||
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
|
||||
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
|
||||
<window_info anchor="bottom" id="TODO" order="6" />
|
||||
<window_info anchor="bottom" id="Version Control" order="7" />
|
||||
<window_info anchor="bottom" id="Terminal" order="8" />
|
||||
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
|
||||
<window_info anchor="bottom" id="Python Console" order="10" />
|
||||
<window_info anchor="right" id="Commander" order="0" weight="0.4" />
|
||||
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
|
||||
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
|
||||
</layout>
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/DecisionTreeGenerate.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="529">
|
||||
<caret line="76" column="51" selection-start-line="76" selection-start-column="51" selection-end-line="76" selection-end-column="51" />
|
||||
<folding>
|
||||
<element signature="e#0#19#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</component>
|
||||
</project>
|
90
Restaurant/Marta/DecisionTreeGenerate.py
Normal file
90
Restaurant/Marta/DecisionTreeGenerate.py
Normal file
@ -0,0 +1,90 @@
|
||||
import pandas as pd
|
||||
import joblib
|
||||
import pydotplus
|
||||
from IPython.display import Image
|
||||
from sklearn import tree
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn.metrics import accuracy_score
|
||||
import os
|
||||
os.environ["PATH"] += os.pathsep + r'C:\Program Files (x86)\Graphviz2.38\bin'
|
||||
|
||||
|
||||
# import danych
|
||||
def dataImport():
|
||||
dataset = pd.read_csv('learnData4.csv', sep=',', header=None)
|
||||
# print(dataset)
|
||||
return dataset
|
||||
|
||||
|
||||
# zamiana dataset na dwie tablice zawierające cechy i wyniki
|
||||
def splitDataSet(dataset):
|
||||
X = dataset.values[:, 0:5]
|
||||
Y = dataset.values[:, 5]
|
||||
|
||||
# podział na zbiory do nauki i testowe
|
||||
x_train, x_test, y_train, y_test = train_test_split(
|
||||
X, Y, test_size=0.3, random_state=100)
|
||||
return X, Y, x_train, x_test, y_train, y_test
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
data = dataImport()
|
||||
X, Y, x_train, x_test, y_train, y_test = splitDataSet(data)
|
||||
|
||||
# utworzenie modelu drzewa decyzyjnego
|
||||
model = tree.DecisionTreeClassifier()
|
||||
model2 = tree.DecisionTreeClassifier(criterion="entropy")
|
||||
|
||||
# przeprowadzenie "nauki" na zbiorach do nauki
|
||||
model.fit(x_train, y_train)
|
||||
model2.fit(x_train, y_train)
|
||||
|
||||
# generowanie wyników dla zbioru testowego
|
||||
pred = model.predict(x_test)
|
||||
pred2 = model2.predict(x_test)
|
||||
|
||||
# porównanie z faktycznymi wynikami = wyliczenie dokładności
|
||||
acc = accuracy_score(y_test, pred) * 100 # aprox. 77.78%
|
||||
acc2 = accuracy_score(y_test, pred2) * 100 # aprox. 83.33%
|
||||
print("akuratnosc dla modelu Gini: " + str(acc))
|
||||
print("akuratnosc dla modelu Entropy: " + str(acc2))
|
||||
|
||||
# przekazanie wygenerowanego modelu do pliku
|
||||
filename = 'finalized_model.sav'
|
||||
joblib.dump(model2, filename)
|
||||
|
||||
kluseczka = [22, 4, 4, 1, 0]
|
||||
wynik = model.predict([kluseczka])
|
||||
print(wynik)
|
||||
|
||||
wynik2 = model2.predict([kluseczka])
|
||||
print(wynik2)
|
||||
|
||||
# wygenerowanie i zapisanie graficznej reprezentacji drzewa
|
||||
# dot_data = tree.export_graphviz(model, out_file=None,
|
||||
# feature_names=["age", "fat", "fiber", "sex", "spicy"],
|
||||
# class_names=["0", "1"],
|
||||
# filled=True, rounded=True,
|
||||
# special_characters=True)
|
||||
|
||||
dot_data2 = tree.export_graphviz(model2, out_file=None,
|
||||
feature_names=["age", "fat", "fiber", "sex", "spicy"],
|
||||
class_names=["easy to digest", "hard to digest"],
|
||||
filled=True, rounded=True,
|
||||
special_characters=True)
|
||||
|
||||
# wygenerowanie grafiki przedstawiającej drzewo
|
||||
# graph = pydotplus.graph_from_dot_data(dot_data)
|
||||
# Image(graph.create_png())
|
||||
# graph.write_png("digest.png")
|
||||
|
||||
graph2 = pydotplus.graph_from_dot_data(dot_data2)
|
||||
Image(graph2.create_png())
|
||||
graph2.write_png("digest_entropy.png")
|
||||
|
||||
|
||||
|
||||
return
|
||||
|
||||
main()
|
@ -3,6 +3,7 @@ import random
|
||||
import time
|
||||
import queue
|
||||
import math
|
||||
import joblib
|
||||
from keras.models import load_model, Sequential
|
||||
from keras.preprocessing.image import img_to_array, load_img
|
||||
from keras.layers import Conv2D, MaxPooling2D
|
||||
@ -123,6 +124,9 @@ class Dish(object):
|
||||
self.preparationTime = prepTime
|
||||
self.eatingTime = eatTime
|
||||
self.price = price
|
||||
self.fatContent = random.randint(0, 16)
|
||||
self.fiberContent = random.randint(0, 16)
|
||||
self.spicy = random.randint(0, 1)
|
||||
|
||||
|
||||
class Plate(object):
|
||||
@ -374,10 +378,10 @@ def classify(a):
|
||||
plate_3 = Plate(dish_1, "Sara/data/validation/dirty/dirty001.png")
|
||||
plate_4 = Plate(dish_3, "Sara/data/validation/dirty/dirty009.png")
|
||||
|
||||
client_1 = Client(21, 'f', 45, 1)
|
||||
client_2 = Client(44, 'm', 22, 4)
|
||||
client_3 = Client(27, 'f', 15, 5)
|
||||
client_4 = Client(19, 'm', 32, 8)
|
||||
client_1 = Client(21, 1, 45, 1)
|
||||
client_2 = Client(44, 0, 22, 4)
|
||||
client_3 = Client(27, 1, 15, 5)
|
||||
client_4 = Client(19, 0, 32, 8)
|
||||
|
||||
client_1.takePlateAndEat(plate_1)
|
||||
client_2.takePlateAndEat(plate_2)
|
||||
@ -412,6 +416,66 @@ def classify(a):
|
||||
pass
|
||||
|
||||
|
||||
def predictDigest(dish, client, model):
|
||||
|
||||
data = []
|
||||
data.append(client.age)
|
||||
data.append(dish.fatContent)
|
||||
data.append(dish.fiberContent)
|
||||
data.append(client.sex)
|
||||
data.append(dish.spicy)
|
||||
|
||||
prediction = model.predict([data])
|
||||
|
||||
if prediction == 1:
|
||||
messagebox.showinfo("opinia", "Z tym może być ciężko. " + str(data))
|
||||
return prediction
|
||||
else:
|
||||
messagebox.showinfo("opinia", "Z tym nie będzie tak źle! " + str(data))
|
||||
return prediction
|
||||
|
||||
|
||||
|
||||
def evaluate(b):
|
||||
if b == 1:
|
||||
loaded_model = joblib.load('Marta/finalized_model.sav')
|
||||
# load = Image.open('Marta/digest_entropy.png')
|
||||
# load.show()
|
||||
messagebox.showinfo("zaczynamy", "Zaczynamy!")
|
||||
|
||||
dish_1 = Dish("obiad", 40, 20, 15)
|
||||
dish_2 = Dish("deser", 25, 10, 10)
|
||||
dish_3 = Dish("obiad 2", 55, 25, 28)
|
||||
|
||||
plate_1 = Plate(dish_1, "Sara/data/validation/food/food004.png")
|
||||
plate_2 = Plate(dish_2, "Sara/data/validation/food/food002.png")
|
||||
plate_4 = Plate(dish_3, "Sara/data/validation/dirty/dirty009.png")
|
||||
|
||||
client_1 = Client(27, 1, 45, 1)
|
||||
client_2 = Client(44, 0, 22, 4)
|
||||
client_4 = Client(16, 0, 32, 8)
|
||||
|
||||
client_1.takePlateAndEat(plate_1)
|
||||
client_2.takePlateAndEat(plate_2)
|
||||
client_4.takePlateAndEat(plate_4)
|
||||
|
||||
bot.goByAStar((tables[1].pos[0] + 1, tables[1].pos[1]))
|
||||
opinion = predictDigest(dish_1, client_1, loaded_model)
|
||||
|
||||
bot.goByAStar((tables[3].pos[0] + 1, tables[3].pos[1]))
|
||||
opinion = predictDigest(dish_2, client_2, loaded_model)
|
||||
|
||||
bot.goByAStar((tables[5].pos[0] + 1, tables[5].pos[1]))
|
||||
opinion = predictDigest(dish_3, client_4, loaded_model)
|
||||
|
||||
messagebox.showinfo("Informacja końcowa", "Zakończono trasę.")
|
||||
|
||||
pygame.quit()
|
||||
exit()
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
def text_objects(text, font):
|
||||
textSurface = font.render(text, True, black)
|
||||
return textSurface, textSurface.get_rect()
|
||||
@ -491,6 +555,8 @@ def makeImgClassificator(model):
|
||||
optimizer='rmsprop',
|
||||
metrics=['accuracy'])
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
global width, rows, bot, light_beige, beige, white, black, sizeBetween, tables, kitchen, cantwalk, puddles, window, clock, \
|
||||
img_classify
|
||||
@ -545,7 +611,7 @@ def main():
|
||||
pygame.quit()
|
||||
quit()
|
||||
button("Rozpoznawanie talerzy", 0, width + 1, 198, 48, light_beige, white, classify)
|
||||
button("Ciężkostrawność dań", 200, width + 1, 198, 48, light_beige, white, "nazwa_funkcji")
|
||||
button("Ciężkostrawność dań", 200, width + 1, 198, 48, light_beige, white, evaluate)
|
||||
redrawWindow(window)
|
||||
|
||||
pygame.quit()
|
||||
|
Loading…
Reference in New Issue
Block a user