Merge remote-tracking branch 'origin/alt_dataset' into tree_increase
This commit is contained in:
commit
d97222e9f5
7
.gitignore
vendored
7
.gitignore
vendored
@ -56,4 +56,9 @@ docs/_build/
|
||||
# Pipfiles
|
||||
|
||||
Pipfile
|
||||
Pipfile.lock
|
||||
Pipfile.lock
|
||||
decision_tree
|
||||
decision_tree.pdf
|
||||
Source.gv.pdf
|
||||
Source.gv
|
||||
decision_tree.txt
|
||||
|
38
TreeConcept.py
Normal file
38
TreeConcept.py
Normal file
@ -0,0 +1,38 @@
|
||||
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/'
|
||||
|
||||
#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 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')
|
||||
#clf = tree.DecisionTreeClassifier(criterion='gini')
|
||||
|
||||
# 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 = [2, 0, 1, 1, 1 ,2, 0]
|
||||
predicted_label = clf.predict([new_example])
|
||||
if predicted_label[0]>0:
|
||||
result="YES"
|
||||
else:
|
||||
result="NO"
|
||||
print("Predicted Label:", result)
|
201
dataset/Dataset.csv
Normal file
201
dataset/Dataset.csv
Normal file
@ -0,0 +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
|
|
200
dataset/converted_dataset.csv
Normal file
200
dataset/converted_dataset.csv
Normal file
@ -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,0,0,0,0
|
||||
3,1,0,0,1,1,0,0
|
||||
1,1,0,1,0,1,1,0
|
||||
2,0,0,1,0,2,1,0
|
||||
2,1,0,1,1,0,1,0
|
||||
2,1,1,0,0,0,1,0
|
||||
3,0,0,0,0,1,1,0
|
||||
2,0,0,1,0,1,1,0
|
||||
1,0,1,0,1,2,0,0
|
||||
3,1,1,0,1,0,1,0
|
||||
2,1,0,1,1,0,0,0
|
||||
2,1,0,1,1,1,0,1
|
||||
0,1,0,0,0,2,1,0
|
||||
1,1,0,0,0,1,0,0
|
||||
1,1,1,0,0,0,0,0
|
||||
2,0,0,1,0,1,0,0
|
||||
1,0,1,1,0,1,0,0
|
||||
2,0,1,1,0,1,1,0
|
||||
1,0,0,0,0,2,0,0
|
||||
2,1,1,1,0,1,1,0
|
||||
3,0,1,0,1,1,0,1
|
||||
0,0,1,1,0,0,1,0
|
||||
3,0,0,0,0,2,1,0
|
||||
2,0,1,1,1,1,0,1
|
||||
2,1,1,1,1,0,0,0
|
||||
0,1,0,1,1,2,0,0
|
||||
0,0,0,0,0,0,0,0
|
||||
2,1,0,0,0,1,0,0
|
||||
2,0,1,1,0,2,1,0
|
||||
3,1,1,0,1,1,1,0
|
||||
2,0,0,1,0,0,1,0
|
||||
1,0,0,0,1,0,0,0
|
||||
3,1,1,1,1,0,1,0
|
||||
3,1,1,1,0,2,1,0
|
||||
1,1,1,1,0,2,1,0
|
||||
1,1,0,0,0,0,1,0
|
||||
2,1,0,0,0,1,1,0
|
||||
3,1,0,1,1,1,1,0
|
||||
1,0,0,0,0,0,0,0
|
||||
3,0,1,0,0,0,1,0
|
||||
2,1,0,1,1,2,0,1
|
||||
1,0,1,1,1,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|
||||
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
|
|
54
dataset/datasetConverter.py
Normal file
54
dataset/datasetConverter.py
Normal file
@ -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")
|
57
dataset/datasetGenerator.py
Normal file
57
dataset/datasetGenerator.py
Normal file
@ -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)
|
33
src/decisionTree/dataset_generator.py
Normal file
33
src/decisionTree/dataset_generator.py
Normal file
@ -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)
|
||||
|
@ -22,6 +22,89 @@ class Waiter(Object):
|
||||
|
||||
def dish_in_basket(self, table) -> bool:
|
||||
return table in self.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
|
||||
|
||||
# importing the dataset from the disk
|
||||
train_data_m = np.genfromtxt(
|
||||
"dataset/converted_dataset.csv", delimiter=",", skip_header=1)
|
||||
|
||||
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/'
|
||||
|
||||
# importing the dataset from the disk
|
||||
train_data_m = np.genfromtxt(
|
||||
"dataset/converted_dataset.csv", delimiter=",", skip_header=1)
|
||||
|
||||
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)
|
||||
|
||||
def basket_is_full(self) -> bool:
|
||||
return self.basket_size == 0
|
||||
|
Loading…
Reference in New Issue
Block a user