From 6126010db153663559d814964b938baae323e39a Mon Sep 17 00:00:00 2001 From: Mirrowel Date: Thu, 18 May 2023 19:17:24 +0200 Subject: [PATCH 1/6] Decision tree test #1 --- 1.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 1.py diff --git a/1.py b/1.py new file mode 100644 index 0000000..eecf7d7 --- /dev/null +++ b/1.py @@ -0,0 +1,25 @@ +from sklearn.datasets import load_iris +from sklearn.tree import DecisionTreeClassifier +from sklearn.model_selection import train_test_split +from sklearn import metrics + +# Load the Iris dataset (or you can use your own dataset) +iris = load_iris() +X = iris.data +y = iris.target + +# Split the dataset into training and testing sets +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) + +# Create an instance of the DecisionTreeClassifier +clf = DecisionTreeClassifier() + +# Train the decision tree classifier +clf.fit(X_train, y_train) + +# Make predictions on the testing set +y_pred = clf.predict(X_test) + +# Evaluate the accuracy of the model +accuracy = metrics.accuracy_score(y_test, y_pred) +print("Accuracy:", accuracy) \ No newline at end of file -- 2.20.1 From 3a8cdc3e932601976c88ea805415a1423d747edf Mon Sep 17 00:00:00 2001 From: Mirrowel Date: Thu, 18 May 2023 20:49:16 +0200 Subject: [PATCH 2/6] Tree #2 --- 1.py | 25 ------------------------- TreeConcept.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 25 deletions(-) delete mode 100644 1.py create mode 100644 TreeConcept.py diff --git a/1.py b/1.py deleted file mode 100644 index eecf7d7..0000000 --- a/1.py +++ /dev/null @@ -1,25 +0,0 @@ -from sklearn.datasets import load_iris -from sklearn.tree import DecisionTreeClassifier -from sklearn.model_selection import train_test_split -from sklearn import metrics - -# Load the Iris dataset (or you can use your own dataset) -iris = load_iris() -X = iris.data -y = iris.target - -# Split the dataset into training and testing sets -X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) - -# Create an instance of the DecisionTreeClassifier -clf = DecisionTreeClassifier() - -# Train the decision tree classifier -clf.fit(X_train, y_train) - -# Make predictions on the testing set -y_pred = clf.predict(X_test) - -# Evaluate the accuracy of the model -accuracy = metrics.accuracy_score(y_test, y_pred) -print("Accuracy:", accuracy) \ No newline at end of file diff --git a/TreeConcept.py b/TreeConcept.py new file mode 100644 index 0000000..2335209 --- /dev/null +++ b/TreeConcept.py @@ -0,0 +1,30 @@ +from sklearn import tree + +# Define the training dataset with 8 attributes and corresponding labels +training_data = [ + [1, 0, 0, 1, 0, 1, 1, 'A'], + [1, 0, 0, 0, 1, 1, 1, 'A'], + [0, 1, 0, 1, 0, 1, 1, 'B'], + [0, 0, 0, 1, 0, 0, 1, 'B'], + [0, 1, 1, 0, 1, 0, 0, 'B'], + [1, 0, 0, 0, 1, 0, 1, 'A'], + [0, 0, 0, 1, 0, 0, 0, 'B'], + [1, 1, 0, 1, 1, 1, 0, 'A'], + [0, 0, 0, 0, 0, 0, 1, 'B'], + [0, 0, 1, 0, 0, 1, 0, 'B'] +] + +# Separate the attributes and labels +X_train = [data[:-1] for data in training_data] +y_train = [data[-1] for data in training_data] + +# Create the decision tree classifier using the ID3 algorithm +clf = tree.DecisionTreeClassifier(criterion='entropy') + +# Train the decision tree on the training data +clf.fit(X_train, y_train) + +# Test the decision tree with a new example +new_example = [1, 0, 0, 1, 1, 0, 0] # Example with 8 attributes +predicted_label = clf.predict([new_example]) +print("Predicted Label:", predicted_label[0]) \ No newline at end of file -- 2.20.1 From 75be644015142e606057c4b4bb414336958b111a Mon Sep 17 00:00:00 2001 From: Mirrowel Date: Thu, 18 May 2023 22:59:37 +0200 Subject: [PATCH 3/6] Tree - Added Graph --- TreeConcept.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/TreeConcept.py b/TreeConcept.py index 2335209..b53512e 100644 --- a/TreeConcept.py +++ b/TreeConcept.py @@ -1,17 +1,20 @@ from sklearn import tree +import graphviz +import os +os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz/bin/' # Define the training dataset with 8 attributes and corresponding labels training_data = [ - [1, 0, 0, 1, 0, 1, 1, 'A'], - [1, 0, 0, 0, 1, 1, 1, 'A'], - [0, 1, 0, 1, 0, 1, 1, 'B'], - [0, 0, 0, 1, 0, 0, 1, 'B'], - [0, 1, 1, 0, 1, 0, 0, 'B'], - [1, 0, 0, 0, 1, 0, 1, 'A'], - [0, 0, 0, 1, 0, 0, 0, 'B'], - [1, 1, 0, 1, 1, 1, 0, 'A'], - [0, 0, 0, 0, 0, 0, 1, 'B'], - [0, 0, 1, 0, 0, 1, 0, 'B'] + [0, 0, 0, 1, 0, 1, 1, 0, 'A'], + [1, 0, 0, 0, 1, 1, 1, 1, 'A'], + [0, 1, 0, 1, 0, 1, 1, 1, 'B'], + [1, 0, 0, 1, 1, 0, 1, 0, 'B'], + [1, 1, 1, 0, 1, 0, 0, 1, 'B'], + [0, 0, 0, 0, 1, 1, 1, 0, 'A'], + [0, 0, 0, 1, 0, 0, 0, 0, 'B'], + [1, 1, 0, 1, 1, 1, 0, 1, 'A'], + [0, 0, 0, 0, 0, 0, 1, 1, 'B'], + [1, 0, 1, 0, 0, 1, 0, 0, 'B'] ] # Separate the attributes and labels @@ -24,7 +27,12 @@ clf = tree.DecisionTreeClassifier(criterion='entropy') # Train the decision tree on the training data clf.fit(X_train, y_train) +# Visualize the trained decision tree +dot_data = tree.export_graphviz(clf, out_file=None, feature_names=['Attr1', 'Attr2', 'Attr3', 'Attr4', 'Attr5', 'Attr6', 'Attr7', 'Attr8'], class_names=['A', 'B'], filled=True) +graph = graphviz.Source(dot_data) +graph.render("decision_tree") # Save the visualization as a PDF file + # Test the decision tree with a new example -new_example = [1, 0, 0, 1, 1, 0, 0] # Example with 8 attributes +new_example = [1, 0, 0, 1, 1, 0, 0, 1] # Example with 8 attributes predicted_label = clf.predict([new_example]) print("Predicted Label:", predicted_label[0]) \ No newline at end of file -- 2.20.1 From 0c34087424936f954c200cf3387d83b7af697fd4 Mon Sep 17 00:00:00 2001 From: Mirrowel Date: Thu, 25 May 2023 22:14:09 +0200 Subject: [PATCH 4/6] Tree - Dataset --- .gitignore | 4 +- TreeConcept.py | 33 +++--- dataset.csv | 288 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 308 insertions(+), 17 deletions(-) create mode 100644 dataset.csv diff --git a/.gitignore b/.gitignore index 686ca0d..cb2ca71 100644 --- a/.gitignore +++ b/.gitignore @@ -56,4 +56,6 @@ docs/_build/ # Pipfiles Pipfile -Pipfile.lock \ No newline at end of file +Pipfile.lock +decision_tree +decision_tree.pdf diff --git a/TreeConcept.py b/TreeConcept.py index b53512e..5324bb7 100644 --- a/TreeConcept.py +++ b/TreeConcept.py @@ -1,26 +1,26 @@ from sklearn import tree +import pandas as pd #for manipulating the csv data +import numpy as np import graphviz import os os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz/bin/' # Define the training dataset with 8 attributes and corresponding labels -training_data = [ - [0, 0, 0, 1, 0, 1, 1, 0, 'A'], - [1, 0, 0, 0, 1, 1, 1, 1, 'A'], - [0, 1, 0, 1, 0, 1, 1, 1, 'B'], - [1, 0, 0, 1, 1, 0, 1, 0, 'B'], - [1, 1, 1, 0, 1, 0, 0, 1, 'B'], - [0, 0, 0, 0, 1, 1, 1, 0, 'A'], - [0, 0, 0, 1, 0, 0, 0, 0, 'B'], - [1, 1, 0, 1, 1, 1, 0, 1, 'A'], - [0, 0, 0, 0, 0, 0, 1, 1, 'B'], - [1, 0, 1, 0, 0, 1, 0, 0, 'B'] -] + +#train_data_m = pd.read_csv("dataset.csv") #importing the dataset from the disk +train_data_m=np.genfromtxt("dataset.csv", delimiter=",",skip_header=1); +#print(train_data_m) +# print(train_data_m) #viewing some row of the dataset # Separate the attributes and labels -X_train = [data[:-1] for data in training_data] -y_train = [data[-1] for data in training_data] +#X_train = [data[:-1] for data in training_data] +#y_train = [data[-1] for data in training_data] +X_train = [data[:-1] for data in train_data_m] +y_train = [data[-1] for data in train_data_m] +#X_train = pd.get_dummies(data[:-1] for data in train_data_m) +#print(X_train) +#print(y_train) # Create the decision tree classifier using the ID3 algorithm clf = tree.DecisionTreeClassifier(criterion='entropy') @@ -28,11 +28,12 @@ clf = tree.DecisionTreeClassifier(criterion='entropy') clf.fit(X_train, y_train) # Visualize the trained decision tree -dot_data = tree.export_graphviz(clf, out_file=None, feature_names=['Attr1', 'Attr2', 'Attr3', 'Attr4', 'Attr5', 'Attr6', 'Attr7', 'Attr8'], class_names=['A', 'B'], filled=True) +dot_data = tree.export_graphviz(clf, out_file=None, feature_names=['Attr1', 'Attr2', 'Attr3', 'Attr4', 'Attr5', 'Attr6', 'Attr7'], class_names=['YES', 'NO'], filled=True) graph = graphviz.Source(dot_data) graph.render("decision_tree") # Save the visualization as a PDF file # Test the decision tree with a new example -new_example = [1, 0, 0, 1, 1, 0, 0, 1] # Example with 8 attributes +#new_example = [1, 0, 0, 1, 1, 0, 0, 1] # Example with 8 attributes +new_example = [2, 0, 0, 1, 1 ,2, 1] # Example with 8 attributes predicted_label = clf.predict([new_example]) print("Predicted Label:", predicted_label[0]) \ No newline at end of file diff --git a/dataset.csv b/dataset.csv new file mode 100644 index 0000000..fe9e66c --- /dev/null +++ b/dataset.csv @@ -0,0 +1,288 @@ +3,1,1,1,1,3,1,0 +3,1,1,1,1,3,0,0 +3,1,1,1,1,2,1,0 +3,1,1,1,1,2,0,0 +3,1,1,1,1,1,1,0 +3,1,1,1,1,1,0,0 +3,1,1,1,0,3,1,0 +3,1,1,1,0,3,0,0 +3,1,1,1,0,2,1,0 +3,1,1,1,0,2,0,0 +3,1,1,1,0,1,1,0 +3,1,1,1,0,1,0,0 +3,1,1,0,1,3,1,0 +3,1,1,0,1,3,0,0 +3,1,1,0,1,2,1,0 +3,1,1,0,1,2,0,0 +3,1,1,0,1,1,1,0 +3,1,1,0,1,1,0,0 +3,1,1,0,0,3,1,0 +3,1,1,0,0,3,0,0 +3,1,1,0,0,2,1,0 +3,1,1,0,0,2,0,0 +3,1,1,0,0,1,1,0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0 +1,0,0,1,1,3,1,0 +1,0,0,1,1,3,0,0 +1,0,0,1,1,2,1,0 +1,0,0,1,1,2,0,0 +1,0,0,1,1,1,1,0 +1,0,0,1,1,1,0,0 +1,0,0,1,0,3,1,0 +1,0,0,1,0,3,0,0 +1,0,0,1,0,2,1,0 +1,0,0,1,0,2,0,0 +1,0,0,1,0,1,1,0 +1,0,0,1,0,1,0,0 +1,0,0,0,1,3,1,0 +1,0,0,0,1,3,0,0 +1,0,0,0,1,2,1,0 +1,0,0,0,1,2,0,0 +1,0,0,0,1,1,1,0 +1,0,0,0,1,1,0,0 +1,0,0,0,0,3,1,0 +1,0,0,0,0,3,0,0 +1,0,0,0,0,2,1,0 +1,0,0,0,0,2,0,0 +1,0,0,0,0,1,1,0 +1,0,0,0,0,1,0,0 \ No newline at end of file -- 2.20.1 From 0c096589d7ea87bc08b46f179e97b85a2fc41c35 Mon Sep 17 00:00:00 2001 From: Mirrowel Date: Fri, 26 May 2023 01:29:28 +0200 Subject: [PATCH 5/6] Tree - Final? --- .gitignore | 3 + TreeConcept.py | 31 ++-- dataset.csv | 288 ---------------------------------- dataset/Dataset.csv | 201 ++++++++++++++++++++++++ dataset/converted_dataset.csv | 200 +++++++++++++++++++++++ dataset/datasetConverter.py | 54 +++++++ dataset/datasetGenerator.py | 57 +++++++ src/obj/Waiter.py | 76 +++++++++ 8 files changed, 606 insertions(+), 304 deletions(-) delete mode 100644 dataset.csv create mode 100644 dataset/Dataset.csv create mode 100644 dataset/converted_dataset.csv create mode 100644 dataset/datasetConverter.py create mode 100644 dataset/datasetGenerator.py diff --git a/.gitignore b/.gitignore index cb2ca71..56bad65 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,6 @@ Pipfile Pipfile.lock decision_tree decision_tree.pdf +Source.gv.pdf +Source.gv +decision_tree.txt diff --git a/TreeConcept.py b/TreeConcept.py index 5324bb7..6f6e857 100644 --- a/TreeConcept.py +++ b/TreeConcept.py @@ -5,35 +5,34 @@ import graphviz import os os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz/bin/' -# Define the training dataset with 8 attributes and corresponding labels - -#train_data_m = pd.read_csv("dataset.csv") #importing the dataset from the disk -train_data_m=np.genfromtxt("dataset.csv", delimiter=",",skip_header=1); -#print(train_data_m) -# print(train_data_m) #viewing some row of the dataset +#importing the dataset from the disk +train_data_m=np.genfromtxt("dataset/converted_dataset.csv", delimiter=",",skip_header=1); # Separate the attributes and labels -#X_train = [data[:-1] for data in training_data] -#y_train = [data[-1] for data in training_data] - X_train = [data[:-1] for data in train_data_m] y_train = [data[-1] for data in train_data_m] -#X_train = pd.get_dummies(data[:-1] for data in train_data_m) -#print(X_train) -#print(y_train) + # Create the decision tree classifier using the ID3 algorithm clf = tree.DecisionTreeClassifier(criterion='entropy') +#clf = tree.DecisionTreeClassifier(criterion='gini') # Train the decision tree on the training data clf.fit(X_train, y_train) # Visualize the trained decision tree -dot_data = tree.export_graphviz(clf, out_file=None, feature_names=['Attr1', 'Attr2', 'Attr3', 'Attr4', 'Attr5', 'Attr6', 'Attr7'], class_names=['YES', 'NO'], filled=True) +tree_text = tree.export_text(clf,feature_names=['Battery Charge', 'Fullness', 'Ready orders', 'Waiting tables','Availability', 'Cleanliness', 'Error']) +with open('decision_tree.txt', 'w') as f: + f.write(tree_text) # Save the visualization as a text file +dot_data = tree.export_graphviz(clf, out_file=None, feature_names=['Battery Charge', 'Fullness', 'Ready orders', 'Waiting tables','Availability', 'Cleanliness', 'Error'], class_names=['NO', 'YES'], filled=True,rounded=True) graph = graphviz.Source(dot_data) graph.render("decision_tree") # Save the visualization as a PDF file # Test the decision tree with a new example -#new_example = [1, 0, 0, 1, 1, 0, 0, 1] # Example with 8 attributes -new_example = [2, 0, 0, 1, 1 ,2, 1] # Example with 8 attributes +#Battery Charge,Fullness,Ready orders,Waiting tables,Availability,Cleanliness,Error +new_example = [2, 0, 1, 1, 1 ,2, 0] predicted_label = clf.predict([new_example]) -print("Predicted Label:", predicted_label[0]) \ No newline at end of file +if predicted_label[0]>0: + result="YES" +else: + result="NO" +print("Predicted Label:", result) \ No newline at end of file diff --git a/dataset.csv b/dataset.csv deleted file mode 100644 index fe9e66c..0000000 --- a/dataset.csv +++ /dev/null @@ -1,288 +0,0 @@ -3,1,1,1,1,3,1,0 -3,1,1,1,1,3,0,0 -3,1,1,1,1,2,1,0 -3,1,1,1,1,2,0,0 -3,1,1,1,1,1,1,0 -3,1,1,1,1,1,0,0 -3,1,1,1,0,3,1,0 -3,1,1,1,0,3,0,0 -3,1,1,1,0,2,1,0 -3,1,1,1,0,2,0,0 -3,1,1,1,0,1,1,0 -3,1,1,1,0,1,0,0 -3,1,1,0,1,3,1,0 -3,1,1,0,1,3,0,0 -3,1,1,0,1,2,1,0 -3,1,1,0,1,2,0,0 -3,1,1,0,1,1,1,0 -3,1,1,0,1,1,0,0 -3,1,1,0,0,3,1,0 -3,1,1,0,0,3,0,0 -3,1,1,0,0,2,1,0 -3,1,1,0,0,2,0,0 -3,1,1,0,0,1,1,0 -3,1,1,0,0,1,0,0 -3,1,0,1,1,3,1,0 -3,1,0,1,1,3,0,0 -3,1,0,1,1,2,1,0 -3,1,0,1,1,2,0,0 -3,1,0,1,1,1,1,0 -3,1,0,1,1,1,0,0 -3,1,0,1,0,3,1,0 -3,1,0,1,0,3,0,0 -3,1,0,1,0,2,1,0 -3,1,0,1,0,2,0,0 -3,1,0,1,0,1,1,0 -3,1,0,1,0,1,0,0 -3,1,0,0,1,3,1,0 -3,1,0,0,1,3,0,0 -3,1,0,0,1,2,1,0 -3,1,0,0,1,2,0,0 -3,1,0,0,1,1,1,0 -3,1,0,0,1,1,0,0 -3,1,0,0,0,3,1,0 -3,1,0,0,0,3,0,0 -3,1,0,0,0,2,1,0 -3,1,0,0,0,2,0,0 -3,1,0,0,0,1,1,0 -3,1,0,0,0,1,0,0 -3,0,1,1,1,3,1,0 -3,0,1,1,1,3,0,0 -3,0,1,1,1,2,1,0 -3,0,1,1,1,2,0,0 -3,0,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+1,201 @@ +Battery Charge,Fullness,Ready orders,Waiting tables,Availability,Cleanliness,Error,To go +high,full,none,none,available,low,yes,no +low,full,none,none,unavailable,medium,yes,no +high,full,none,none,unavailable,medium,no,no +medium,empty,none,none,unavailable,low,no,no +high,full,none,none,available,medium,no,no +low,full,none,available,unavailable,medium,yes,no +medium,empty,none,available,unavailable,high,yes,no +medium,full,none,available,available,low,yes,no +medium,full,available,none,unavailable,low,yes,no +high,empty,none,none,unavailable,medium,yes,no +medium,empty,none,available,unavailable,medium,yes,no +low,empty,available,none,available,high,no,no +high,full,available,none,available,low,yes,no +medium,full,none,available,available,low,no,no +medium,full,none,available,available,medium,no,yes +empty,full,none,none,unavailable,high,yes,no +low,full,none,none,unavailable,medium,no,no +low,full,available,none,unavailable,low,no,no +medium,empty,none,available,unavailable,medium,no,no +low,empty,available,available,unavailable,medium,no,no +medium,empty,available,available,unavailable,medium,yes,no +low,empty,none,none,unavailable,high,no,no +medium,full,available,available,unavailable,medium,yes,no +high,empty,available,none,available,medium,no,yes +empty,empty,available,available,unavailable,low,yes,no +high,empty,none,none,unavailable,high,yes,no +medium,empty,available,available,available,medium,no,yes +medium,full,available,available,available,low,no,no +empty,full,none,available,available,high,no,no +empty,empty,none,none,unavailable,low,no,no +medium,full,none,none,unavailable,medium,no,no +medium,empty,available,available,unavailable,high,yes,no +high,full,available,none,available,medium,yes,no +medium,empty,none,available,unavailable,low,yes,no +low,empty,none,none,available,low,no,no +high,full,available,available,available,low,yes,no +high,full,available,available,unavailable,high,yes,no +low,full,available,available,unavailable,high,yes,no +low,full,none,none,unavailable,low,yes,no +medium,full,none,none,unavailable,medium,yes,no +high,full,none,available,available,medium,yes,no +low,empty,none,none,unavailable,low,no,no +high,empty,available,none,unavailable,low,yes,no +medium,full,none,available,available,high,no,yes +low,empty,available,available,available,high,yes,no +low,full,available,none,unavailable,high,yes,no +medium,full,available,none,unavailable,low,no,no +medium,full,available,available,unavailable,high,no,no +medium,full,none,available,unavailable,low,yes,no +medium,empty,available,none,unavailable,low,yes,no +medium,empty,none,none,available,high,no,no +empty,full,none,none,available,low,no,no +low,full,available,available,available,medium,yes,no +low,full,available,none,unavailable,high,no,no +high,full,available,none,available,medium,no,no +low,full,none,available,available,medium,no,no +empty,empty,none,available,available,high,no,no +low,full,none,available,unavailable,low,no,no +high,full,none,none,unavailable,high,no,no +medium,full,none,none,available,high,yes,no +low,empty,none,available,available,medium,no,no +empty,empty,none,available,unavailable,low,no,no +empty,full,available,none,available,low,yes,no +empty,empty,available,available,available,medium,no,no +empty,empty,available,none,unavailable,medium,no,no +empty,empty,none,none,unavailable,high,no,no +medium,empty,available,none,unavailable,high,no,no +empty,empty,available,none,available,medium,yes,no +empty,empty,none,none,unavailable,high,yes,no +high,full,available,available,unavailable,low,no,no +high,empty,available,available,available,high,yes,no +high,empty,available,none,available,low,no,no +low,empty,none,available,unavailable,medium,no,no +medium,full,none,available,unavailable,low,no,no +medium,empty,none,available,available,high,yes,no +medium,empty,available,available,available,high,no,yes +high,empty,none,available,unavailable,low,yes,no +low,full,available,available,available,high,no,no +medium,empty,none,available,available,high,no,no +medium,empty,available,none,available,high,no,yes +empty,full,available,available,unavailable,high,no,no +low,empty,none,available,available,low,no,no +high,full,none,available,available,low,yes,no +high,empty,none,none,available,medium,yes,no +empty,empty,available,none,unavailable,low,no,no +high,full,none,available,unavailable,low,yes,no +empty,full,none,available,unavailable,high,no,no +empty,full,available,none,available,low,no,no +medium,full,none,none,available,high,no,no +medium,full,available,available,unavailable,low,yes,no +empty,full,available,available,unavailable,low,yes,no +low,empty,none,none,unavailable,medium,no,no +low,full,none,none,unavailable,low,no,no +low,full,available,available,unavailable,low,yes,no +low,empty,none,available,available,low,yes,no +empty,full,available,none,unavailable,high,no,no +low,full,available,none,available,high,no,no +high,full,available,available,available,medium,yes,no +empty,full,none,available,available,medium,yes,no +low,full,none,none,available,medium,no,no +empty,full,available,available,available,low,no,no +medium,full,available,none,unavailable,medium,yes,no +empty,empty,none,none,available,medium,no,no +high,full,none,available,unavailable,low,no,no +low,empty,available,available,available,high,no,no +low,empty,none,available,available,high,yes,no +high,full,none,available,available,medium,no,yes +empty,full,available,none,available,medium,yes,no +high,full,none,none,available,low,no,no +low,empty,available,available,unavailable,high,no,no +low,full,available,none,available,medium,yes,no +high,empty,none,none,unavailable,low,no,no +low,full,none,none,unavailable,high,yes,no +high,empty,none,available,available,low,yes,no +empty,full,available,available,unavailable,low,no,no +low,empty,available,available,unavailable,low,no,no +low,full,available,none,unavailable,low,yes,no +empty,empty,available,available,unavailable,high,no,no +medium,full,available,none,available,medium,yes,no +high,full,available,none,available,high,no,no +low,full,none,available,available,medium,yes,no +low,empty,none,available,unavailable,medium,yes,no +high,full,available,available,unavailable,medium,yes,no +high,full,none,none,unavailable,medium,yes,no +low,full,available,available,available,low,yes,no +low,full,available,available,unavailable,high,no,no +empty,full,none,none,available,medium,no,no +empty,empty,available,none,available,low,yes,no +high,full,available,none,unavailable,high,no,no +high,full,none,available,unavailable,high,no,no +low,empty,available,available,unavailable,medium,yes,no +high,empty,available,available,available,low,yes,no +empty,full,none,none,unavailable,low,no,no +high,full,none,available,unavailable,medium,yes,no +high,empty,available,none,unavailable,medium,no,no +empty,empty,available,none,available,high,yes,no +high,empty,available,none,unavailable,medium,yes,no +empty,empty,none,none,unavailable,medium,no,no +high,empty,none,available,available,high,no,no +medium,empty,none,none,unavailable,low,yes,no +medium,full,available,none,unavailable,high,no,no +high,full,none,none,unavailable,low,no,no +high,empty,none,none,unavailable,medium,no,no +medium,full,available,none,available,low,no,no +high,empty,none,none,available,high,yes,no +empty,full,available,available,available,high,no,no +medium,full,available,available,unavailable,low,no,no +empty,full,available,none,available,medium,no,no +empty,full,available,available,unavailable,medium,yes,no +empty,empty,available,none,available,high,no,no +low,empty,none,none,available,high,yes,no +empty,full,none,available,unavailable,medium,yes,no +medium,full,none,available,unavailable,medium,yes,no +medium,full,available,none,available,low,yes,no +medium,full,available,none,unavailable,high,yes,no +medium,full,available,available,available,high,no,yes +medium,full,none,none,available,low,no,no +high,full,none,available,available,high,no,yes +low,empty,available,available,unavailable,low,yes,no +low,full,none,available,unavailable,high,yes,no +medium,full,available,available,available,high,yes,no +high,full,available,available,available,low,no,no +medium,full,none,none,unavailable,high,yes,no +medium,full,none,available,unavailable,high,no,no +high,empty,none,available,unavailable,high,yes,no +empty,empty,none,available,available,medium,no,no +empty,empty,available,none,unavailable,high,no,no +high,empty,available,available,unavailable,high,yes,no +medium,empty,available,available,unavailable,low,yes,no +medium,full,none,none,unavailable,low,no,no +high,empty,none,none,available,low,no,no +high,full,available,none,unavailable,medium,no,no +high,full,available,none,unavailable,low,yes,no +empty,empty,available,available,available,low,yes,no +high,empty,none,none,unavailable,low,yes,no +medium,empty,none,none,available,low,no,no +low,full,none,available,unavailable,medium,no,no +low,full,none,available,available,high,yes,no +high,full,none,available,unavailable,high,yes,no +medium,full,none,available,available,medium,yes,no +empty,empty,none,available,unavailable,high,yes,no +medium,empty,available,none,unavailable,medium,yes,no +empty,empty,none,available,unavailable,low,yes,no +high,empty,none,available,unavailable,medium,no,no +medium,empty,available,none,available,low,yes,no +medium,full,available,available,available,medium,no,yes +high,full,available,none,unavailable,medium,yes,no +high,full,available,available,unavailable,medium,no,no +low,full,available,none,available,medium,no,no +medium,empty,available,none,unavailable,high,yes,no +medium,empty,available,none,available,medium,yes,no +high,empty,none,none,available,high,no,no +empty,full,available,none,unavailable,high,yes,no +low,empty,available,none,unavailable,low,yes,no +empty,full,available,available,available,low,yes,no +medium,empty,available,available,unavailable,medium,no,no +medium,empty,none,none,unavailable,high,no,no +medium,full,available,available,unavailable,medium,no,no +empty,full,available,available,available,medium,no,no +low,empty,available,none,available,low,no,no diff --git a/dataset/converted_dataset.csv b/dataset/converted_dataset.csv new file mode 100644 index 0000000..ff324f2 --- /dev/null +++ b/dataset/converted_dataset.csv @@ -0,0 +1,200 @@ +3,1,0,0,1,0,1,0 +1,1,0,0,0,1,1,0 +3,1,0,0,0,1,0,0 +2,0,0,0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0,1,0,1,0,1,0 +2,1,1,1,1,1,0,1 +3,1,1,0,0,1,1,0 +3,1,1,1,0,1,0,0 +1,1,1,0,1,1,0,0 +2,0,1,0,0,2,1,0 +2,0,1,0,1,1,1,0 +3,0,0,0,1,2,0,0 +0,1,1,0,0,2,1,0 +1,0,1,0,0,0,1,0 +0,1,1,1,1,0,1,0 +2,0,1,1,0,1,0,0 +2,0,0,0,0,2,0,0 +2,1,1,1,0,1,0,0 +0,1,1,1,1,1,0,0 +1,0,1,0,1,0,0,0 diff --git a/dataset/datasetConverter.py b/dataset/datasetConverter.py new file mode 100644 index 0000000..ade5bca --- /dev/null +++ b/dataset/datasetConverter.py @@ -0,0 +1,54 @@ +import csv + +def convert_dataset(input_file, output_file): + attributes = { + 1: ["empty", "low", "medium", "high"], + 2: ["empty", "full"], + 3: ["none", "available"], + 4: ["none", "available"], + 5: ["unavailable", "available"], + 6: ["low", "medium", "high"], + 7: ["no", "yes"], + 8: ["no", "yes"] + } + + # Create a mapping dictionary for attribute values + mapping = {} + for attr, values in attributes.items(): + mapping[attr] = {value: index for index, value in enumerate(values)} + + converted_dataset = [] + + # Read the input CSV file + with open(input_file, "r") as csvfile: + reader = csv.reader(csvfile) + + header = next(reader) # Skip the header row + + # Convert the data rows + for row in reader: + converted_row = [] + for i, value in enumerate(row): + # Convert the attribute values + if i + 1 in mapping: + converted_value = mapping[i + 1][value] + else: + converted_value = value + + converted_row.append(converted_value) + + converted_dataset.append(converted_row) + + # Write the converted dataset to a new CSV file + with open(output_file, "w", newline="") as csvfile: + writer = csv.writer(csvfile) + + # Write the header row + #writer.writerow(header) + + # Write the converted data rows + for row in converted_dataset: + writer.writerow(row) + +# Example usage: +convert_dataset("dataset/Dataset.csv", "dataset/converted_dataset.csv") \ No newline at end of file diff --git a/dataset/datasetGenerator.py b/dataset/datasetGenerator.py new file mode 100644 index 0000000..b525b04 --- /dev/null +++ b/dataset/datasetGenerator.py @@ -0,0 +1,57 @@ +import random +import csv + +attributes = { + 1: ["empty", "low", "medium", "high"], + 2: ["empty", "full"], + 3: ["none", "available"], + 4: ["none", "available"], + 5: ["unavailable", "available"], + 6: ["low", "medium", "high"], + 7: ["no", "yes"], + 8: ["no", "yes"] +} + +dataset = [] +while len(dataset) < 200: + data = {} + + # Generate random values for attributes 1-7 + for attr in range(1, 8): + data[attr] = random.choice(attributes[attr]) + + # Apply the rules to determine the value of attribute 8 + if data[1] in ["empty", "low"]: + data[8] = "no" + elif data[2] == "full" and data[4] == "none": + data[8] = "no" + elif data[2] == "empty" and data[3] == "none": + data[8] = "no" + elif data[3] == "none" and data[4] == "none": + data[8] = "no" + elif data[5] == "unavailable": + data[8] = "no" + elif data[6] == "low": + data[8] = "no" + elif data[7] == "yes": + data[8] = "no" + else: + data[8] = "yes" + + # Check if the generated data already exists in the dataset + if data not in dataset: + dataset.append(data) + +# Print the generated dataset +for data in dataset: + print(data) +with open("dataset/Dataset.csv", "w", newline="") as csvfile: + writer = csv.writer(csvfile) + + # Write the header row + writer.writerow(["Battery Charge", "Fullness", "Ready orders", "Waiting tables","Availability", "Cleanliness", "Error", "To go"]) + + # Write the data rows + for data in dataset: + row = [data[attr] for attr in range(1, 9)] + writer.writerow(row) \ No newline at end of file diff --git a/src/obj/Waiter.py b/src/obj/Waiter.py index 2c4d232..23407fe 100644 --- a/src/obj/Waiter.py +++ b/src/obj/Waiter.py @@ -6,6 +6,12 @@ class Waiter(Object): def __init__(self, position, orientation, square_size, screen_size, basket=[]): super().__init__("waiter", position, orientation, square_size, screen_size) self.basket_size = 2 + self.battery=2 + self.orderReadiness=1 + self.waitingTables=1 + self.availability=1 + self.cleanliness=2 + self.error=1 self.basket = basket self.prev_position = copy.deepcopy(self.position) self.prev_orientation = copy.copy(self.orientation) @@ -14,8 +20,78 @@ class Waiter(Object): self.position = copy.deepcopy(state.position) self.orientation = copy.copy(state.orientation) self.basket = copy.copy(state.basket) + self.calcTree() return state + def calcTree(self): + from sklearn import tree + import pandas as pd #for manipulating the csv data + import numpy as np + import os + + train_data_m=np.genfromtxt("dataset/converted_dataset.csv", delimiter=",",skip_header=1); #importing the dataset from the disk + + + X_train = [data[:-1] for data in train_data_m] + y_train = [data[-1] for data in train_data_m] + # Create the decision tree classifier using the ID3 algorithm + clf = tree.DecisionTreeClassifier(criterion='entropy') + + # Train the decision tree on the training data + clf.fit(X_train, y_train) + + # Visualize the trained decision tree + tree_text = tree.export_text(clf,feature_names=['Battery Charge', 'Fullness', 'Ready orders', 'Waiting tables','Availability', 'Cleanliness', 'Error']) + with open('decision_tree.txt', 'w') as f: + f.write(tree_text) # Save the visualization as a text file + + # Test the decision tree with a new example + #Battery Charge,Fullness,Ready orders,Waiting tables,Availability,Cleanliness,Error + new_example = [self.battery, 0,self.orderReadiness,self.waitingTables,self.availability, self.cleanliness, self.error] + predicted_label = clf.predict([new_example]) + if predicted_label[0]>0: + result="YES" + else: + result="NO" + print("Predicted Label:", result) + + def calcTreePDF(self): + from sklearn import tree + import pandas as pd #for manipulating the csv data + import numpy as np + import graphviz + import os + os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz/bin/' + + train_data_m=np.genfromtxt("dataset/converted_dataset.csv", delimiter=",",skip_header=1); #importing the dataset from the disk + + + X_train = [data[:-1] for data in train_data_m] + y_train = [data[-1] for data in train_data_m] + # Create the decision tree classifier using the ID3 algorithm + clf = tree.DecisionTreeClassifier(criterion='entropy') + + # Train the decision tree on the training data + clf.fit(X_train, y_train) + + # Visualize the trained decision tree + tree_text = tree.export_text(clf,feature_names=['Battery Charge', 'Fullness', 'Ready orders', 'Waiting tables','Availability', 'Cleanliness', 'Error']) + with open('decision_tree.txt', 'w') as f: + f.write(tree_text) # Save the visualization as a text file + dot_data = tree.export_graphviz(clf, out_file=None, feature_names=['Battery Charge', 'Fullness', 'Ready orders', 'Waiting tables','Availability', 'Cleanliness', 'Error'], class_names=['NO', 'YES'], filled=True,rounded=True) + graph = graphviz.Source(dot_data) + graph.render("decision_tree") # Save the visualization as a PDF file + + # Test the decision tree with a new example + #Battery Charge,Fullness,Ready orders,Waiting tables,Availability,Cleanliness,Error + new_example = [self.battery, 0,self.orderReadiness,self.waitingTables,self.availability, self.cleanliness, self.error] + predicted_label = clf.predict([new_example]) + if predicted_label[0]>0: + result="YES" + else: + result="NO" + print("Predicted Label:", result) + def dampState(self): self.prev_position = copy.deepcopy(self.position) self.prev_orientation = copy.copy(self.orientation) -- 2.20.1 From 255e45fd93a3c1046a785df47711de7be700bcb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Ry=C5=BCek?= Date: Fri, 26 May 2023 02:10:21 +0200 Subject: [PATCH 6/6] added alternate dataset --- src/decisionTree/dataset_generator.py | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/decisionTree/dataset_generator.py diff --git a/src/decisionTree/dataset_generator.py b/src/decisionTree/dataset_generator.py new file mode 100644 index 0000000..99b7a1f --- /dev/null +++ b/src/decisionTree/dataset_generator.py @@ -0,0 +1,33 @@ +import csv +import random + +battery_values = ['high', 'medium', 'low'] +distance_values = ['far', 'medium', 'close'] +mood_values = ['good', 'medium', 'bad'] +other = ['yes', 'no'] + + +training_data = [] + +for _ in range(200): + battery = random.choice(battery_values) + distance = random.choice(distance_values) + mood = random.choice(mood_values) + memory = random.randint(0,4) + dishes_held = random.randint(0,4) + """empty_basket = random.choice(other) + if empty_basket == 'yes': + dish_in_basket = 'no' + else: + dish_in_basket = random.choice(other) + dish_in_basket = random.choice(other)""" + waiting_for_order = random.choice(other) + waiting_for_dish = random.choice(other) + + example = [battery, distance, mood, memory, dishes_held, waiting_for_order, waiting_for_dish] + training_data.append(example) + +with open('data.csv', 'w', newline='') as file: + writer = csv.writer(file) + writer.writerows(training_data) + -- 2.20.1