alt_dataset #1
3
.gitignore
vendored
3
.gitignore
vendored
@ -59,3 +59,6 @@ Pipfile
|
|||||||
Pipfile.lock
|
Pipfile.lock
|
||||||
decision_tree
|
decision_tree
|
||||||
decision_tree.pdf
|
decision_tree.pdf
|
||||||
|
Source.gv.pdf
|
||||||
|
Source.gv
|
||||||
|
decision_tree.txt
|
||||||
|
@ -5,35 +5,34 @@ import graphviz
|
|||||||
import os
|
import os
|
||||||
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz/bin/'
|
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz/bin/'
|
||||||
|
|
||||||
# Define the training dataset with 8 attributes and corresponding labels
|
#importing the dataset from the disk
|
||||||
|
train_data_m=np.genfromtxt("dataset/converted_dataset.csv", delimiter=",",skip_header=1);
|
||||||
#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
|
# 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]
|
X_train = [data[:-1] for data in train_data_m]
|
||||||
y_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
|
# Create the decision tree classifier using the ID3 algorithm
|
||||||
clf = tree.DecisionTreeClassifier(criterion='entropy')
|
clf = tree.DecisionTreeClassifier(criterion='entropy')
|
||||||
|
#clf = tree.DecisionTreeClassifier(criterion='gini')
|
||||||
|
|
||||||
# Train the decision tree on the training data
|
# Train the decision tree on the training data
|
||||||
clf.fit(X_train, y_train)
|
clf.fit(X_train, y_train)
|
||||||
|
|
||||||
# Visualize the trained decision tree
|
# 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 = graphviz.Source(dot_data)
|
||||||
graph.render("decision_tree") # Save the visualization as a PDF file
|
graph.render("decision_tree") # Save the visualization as a PDF file
|
||||||
|
|
||||||
# Test the decision tree with a new example
|
# Test the decision tree with a new example
|
||||||
#new_example = [1, 0, 0, 1, 1, 0, 0, 1] # Example with 8 attributes
|
#Battery Charge,Fullness,Ready orders,Waiting tables,Availability,Cleanliness,Error
|
||||||
new_example = [2, 0, 0, 1, 1 ,2, 1] # Example with 8 attributes
|
new_example = [2, 0, 1, 1, 1 ,2, 0]
|
||||||
predicted_label = clf.predict([new_example])
|
predicted_label = clf.predict([new_example])
|
||||||
print("Predicted Label:", predicted_label[0])
|
if predicted_label[0]>0:
|
||||||
|
result="YES"
|
||||||
|
else:
|
||||||
|
result="NO"
|
||||||
|
print("Predicted Label:", result)
|
288
dataset.csv
288
dataset.csv
@ -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,1,1,1,1,1,0
|
|
||||||
3,0,1,1,1,1,0,0
|
|
||||||
3,0,1,1,0,3,1,0
|
|
||||||
3,0,1,1,0,3,0,0
|
|
||||||
3,0,1,1,0,2,1,0
|
|
||||||
3,0,1,1,0,2,0,0
|
|
||||||
3,0,1,1,0,1,1,0
|
|
||||||
3,0,1,1,0,1,0,0
|
|
||||||
3,0,1,0,1,3,1,0
|
|
||||||
3,0,1,0,1,3,0,0
|
|
||||||
3,0,1,0,1,2,1,0
|
|
||||||
3,0,1,0,1,2,0,0
|
|
||||||
3,0,1,0,1,1,1,0
|
|
||||||
3,0,1,0,1,1,0,0
|
|
||||||
3,0,1,0,0,3,1,0
|
|
||||||
3,0,1,0,0,3,0,0
|
|
||||||
3,0,1,0,0,2,1,0
|
|
||||||
3,0,1,0,0,2,0,0
|
|
||||||
3,0,1,0,0,1,1,0
|
|
||||||
3,0,1,0,0,1,0,0
|
|
||||||
3,0,0,1,1,3,1,0
|
|
||||||
3,0,0,1,1,3,0,0
|
|
||||||
3,0,0,1,1,2,1,0
|
|
||||||
3,0,0,1,1,2,0,1
|
|
||||||
3,0,0,1,1,1,1,0
|
|
||||||
3,0,0,1,1,1,0,1
|
|
||||||
3,0,0,1,0,3,1,0
|
|
||||||
3,0,0,1,0,3,0,0
|
|
||||||
3,0,0,1,0,2,1,0
|
|
||||||
3,0,0,1,0,2,0,0
|
|
||||||
3,0,0,1,0,1,1,0
|
|
||||||
3,0,0,1,0,1,0,0
|
|
||||||
3,0,0,0,1,3,1,0
|
|
||||||
3,0,0,0,1,3,0,0
|
|
||||||
3,0,0,0,1,2,1,0
|
|
||||||
3,0,0,0,1,2,0,1
|
|
||||||
3,0,0,0,1,1,1,0
|
|
||||||
3,0,0,0,1,1,0,1
|
|
||||||
3,0,0,0,0,3,1,0
|
|
||||||
3,0,0,0,0,3,0,0
|
|
||||||
3,0,0,0,0,2,1,1
|
|
||||||
3,0,0,0,0,2,0,1
|
|
||||||
3,0,0,0,0,1,1,1
|
|
||||||
3,0,0,0,0,1,0,1
|
|
||||||
2,1,1,1,1,3,1,0
|
|
||||||
2,1,1,1,1,3,0,0
|
|
||||||
2,1,1,1,1,2,1,0
|
|
||||||
2,1,1,1,1,2,0,0
|
|
||||||
2,1,1,1,1,1,1,0
|
|
||||||
2,1,1,1,1,1,0,0
|
|
||||||
2,1,1,1,0,3,1,0
|
|
||||||
2,1,1,1,0,3,0,0
|
|
||||||
2,1,1,1,0,2,1,0
|
|
||||||
2,1,1,1,0,2,0,0
|
|
||||||
2,1,1,1,0,1,1,0
|
|
||||||
2,1,1,1,0,1,0,0
|
|
||||||
2,1,1,0,1,3,1,0
|
|
||||||
2,1,1,0,1,3,0,0
|
|
||||||
2,1,1,0,1,2,1,0
|
|
||||||
2,1,1,0,1,2,0,0
|
|
||||||
2,1,1,0,1,1,1,0
|
|
||||||
2,1,1,0,1,1,0,0
|
|
||||||
2,1,1,0,0,3,1,0
|
|
||||||
2,1,1,0,0,3,0,0
|
|
||||||
2,1,1,0,0,2,1,0
|
|
||||||
2,1,1,0,0,2,0,0
|
|
||||||
2,1,1,0,0,1,1,0
|
|
||||||
2,1,1,0,0,1,0,0
|
|
||||||
2,1,0,1,1,3,1,0
|
|
||||||
2,1,0,1,1,3,0,0
|
|
||||||
2,1,0,1,1,2,1,0
|
|
||||||
2,1,0,1,1,2,0,0
|
|
||||||
2,1,0,1,1,1,1,0
|
|
||||||
2,1,0,1,1,1,0,0
|
|
||||||
2,1,0,1,0,3,1,0
|
|
||||||
2,1,0,1,0,3,0,0
|
|
||||||
2,1,0,1,0,2,1,0
|
|
||||||
2,1,0,1,0,2,0,0
|
|
||||||
2,1,0,1,0,1,1,0
|
|
||||||
2,1,0,1,0,1,0,0
|
|
||||||
2,1,0,0,1,3,1,0
|
|
||||||
2,1,0,0,1,3,0,0
|
|
||||||
2,1,0,0,1,2,1,0
|
|
||||||
2,1,0,0,1,2,0,0
|
|
||||||
2,1,0,0,1,1,1,0
|
|
||||||
2,1,0,0,1,1,0,0
|
|
||||||
2,1,0,0,0,3,1,0
|
|
||||||
2,1,0,0,0,3,0,0
|
|
||||||
2,1,0,0,0,2,1,0
|
|
||||||
2,1,0,0,0,2,0,0
|
|
||||||
2,1,0,0,0,1,1,0
|
|
||||||
2,1,0,0,0,1,0,0
|
|
||||||
2,0,1,1,1,3,1,0
|
|
||||||
2,0,1,1,1,3,0,0
|
|
||||||
2,0,1,1,1,2,1,0
|
|
||||||
2,0,1,1,1,2,0,0
|
|
||||||
2,0,1,1,1,1,1,0
|
|
||||||
2,0,1,1,1,1,0,0
|
|
||||||
2,0,1,1,0,3,1,0
|
|
||||||
2,0,1,1,0,3,0,0
|
|
||||||
2,0,1,1,0,2,1,0
|
|
||||||
2,0,1,1,0,2,0,0
|
|
||||||
2,0,1,1,0,1,1,0
|
|
||||||
2,0,1,1,0,1,0,0
|
|
||||||
2,0,1,0,1,3,1,0
|
|
||||||
2,0,1,0,1,3,0,0
|
|
||||||
2,0,1,0,1,2,1,0
|
|
||||||
2,0,1,0,1,2,0,0
|
|
||||||
2,0,1,0,1,1,1,0
|
|
||||||
2,0,1,0,1,1,0,0
|
|
||||||
2,0,1,0,0,3,1,0
|
|
||||||
2,0,1,0,0,3,0,0
|
|
||||||
2,0,1,0,0,2,1,0
|
|
||||||
2,0,1,0,0,2,0,0
|
|
||||||
2,0,1,0,0,1,1,0
|
|
||||||
2,0,1,0,0,1,0,0
|
|
||||||
2,0,0,1,1,3,1,0
|
|
||||||
2,0,0,1,1,3,0,0
|
|
||||||
2,0,0,1,1,2,1,0
|
|
||||||
2,0,0,1,1,2,0,1
|
|
||||||
2,0,0,1,1,1,1,0
|
|
||||||
2,0,0,1,1,1,0,1
|
|
||||||
2,0,0,1,0,3,1,0
|
|
||||||
2,0,0,1,0,3,0,0
|
|
||||||
2,0,0,1,0,2,1,0
|
|
||||||
2,0,0,1,0,2,0,0
|
|
||||||
2,0,0,1,0,1,1,0
|
|
||||||
2,0,0,1,0,1,0,0
|
|
||||||
2,0,0,0,1,3,1,0
|
|
||||||
2,0,0,0,1,3,0,0
|
|
||||||
2,0,0,0,1,2,1,0
|
|
||||||
2,0,0,0,1,2,0,1
|
|
||||||
2,0,0,0,1,1,1,0
|
|
||||||
2,0,0,0,1,1,0,1
|
|
||||||
2,0,0,0,0,3,1,0
|
|
||||||
2,0,0,0,0,3,0,0
|
|
||||||
2,0,0,0,0,2,1,1
|
|
||||||
2,0,0,0,0,2,0,1
|
|
||||||
2,0,0,0,0,1,1,1
|
|
||||||
2,0,0,0,0,1,0,1
|
|
||||||
1,1,1,1,1,3,1,0
|
|
||||||
1,1,1,1,1,3,0,0
|
|
||||||
1,1,1,1,1,2,1,0
|
|
||||||
1,1,1,1,1,2,0,0
|
|
||||||
1,1,1,1,1,1,1,0
|
|
||||||
1,1,1,1,1,1,0,0
|
|
||||||
1,1,1,1,0,3,1,0
|
|
||||||
1,1,1,1,0,3,0,0
|
|
||||||
1,1,1,1,0,2,1,0
|
|
||||||
1,1,1,1,0,2,0,0
|
|
||||||
1,1,1,1,0,1,1,0
|
|
||||||
1,1,1,1,0,1,0,0
|
|
||||||
1,1,1,0,1,3,1,0
|
|
||||||
1,1,1,0,1,3,0,0
|
|
||||||
1,1,1,0,1,2,1,0
|
|
||||||
1,1,1,0,1,2,0,0
|
|
||||||
1,1,1,0,1,1,1,0
|
|
||||||
1,1,1,0,1,1,0,0
|
|
||||||
1,1,1,0,0,3,1,0
|
|
||||||
1,1,1,0,0,3,0,0
|
|
||||||
1,1,1,0,0,2,1,0
|
|
||||||
1,1,1,0,0,2,0,0
|
|
||||||
1,1,1,0,0,1,1,0
|
|
||||||
1,1,1,0,0,1,0,0
|
|
||||||
1,1,0,1,1,3,1,0
|
|
||||||
1,1,0,1,1,3,0,0
|
|
||||||
1,1,0,1,1,2,1,0
|
|
||||||
1,1,0,1,1,2,0,0
|
|
||||||
1,1,0,1,1,1,1,0
|
|
||||||
1,1,0,1,1,1,0,0
|
|
||||||
1,1,0,1,0,3,1,0
|
|
||||||
1,1,0,1,0,3,0,0
|
|
||||||
1,1,0,1,0,2,1,0
|
|
||||||
1,1,0,1,0,2,0,0
|
|
||||||
1,1,0,1,0,1,1,0
|
|
||||||
1,1,0,1,0,1,0,0
|
|
||||||
1,1,0,0,1,3,1,0
|
|
||||||
1,1,0,0,1,3,0,0
|
|
||||||
1,1,0,0,1,2,1,0
|
|
||||||
1,1,0,0,1,2,0,0
|
|
||||||
1,1,0,0,1,1,1,0
|
|
||||||
1,1,0,0,1,1,0,0
|
|
||||||
1,1,0,0,0,3,1,0
|
|
||||||
1,1,0,0,0,3,0,0
|
|
||||||
1,1,0,0,0,2,1,0
|
|
||||||
1,1,0,0,0,2,0,0
|
|
||||||
1,1,0,0,0,1,1,0
|
|
||||||
1,1,0,0,0,1,0,0
|
|
||||||
1,0,1,1,1,3,1,0
|
|
||||||
1,0,1,1,1,3,0,0
|
|
||||||
1,0,1,1,1,2,1,0
|
|
||||||
1,0,1,1,1,2,0,0
|
|
||||||
1,0,1,1,1,1,1,0
|
|
||||||
1,0,1,1,1,1,0,0
|
|
||||||
1,0,1,1,0,3,1,0
|
|
||||||
1,0,1,1,0,3,0,0
|
|
||||||
1,0,1,1,0,2,1,0
|
|
||||||
1,0,1,1,0,2,0,0
|
|
||||||
1,0,1,1,0,1,1,0
|
|
||||||
1,0,1,1,0,1,0,0
|
|
||||||
1,0,1,0,1,3,1,0
|
|
||||||
1,0,1,0,1,3,0,0
|
|
||||||
1,0,1,0,1,2,1,0
|
|
||||||
1,0,1,0,1,2,0,0
|
|
||||||
1,0,1,0,1,1,1,0
|
|
||||||
1,0,1,0,1,1,0,0
|
|
||||||
1,0,1,0,0,3,1,0
|
|
||||||
1,0,1,0,0,3,0,0
|
|
||||||
1,0,1,0,0,2,1,0
|
|
||||||
1,0,1,0,0,2,0,0
|
|
||||||
1,0,1,0,0,1,1,0
|
|
||||||
1,0,1,0,0,1,0,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
|
|
|