more trainig examples, model training #31

Merged
s473616 merged 1 commits from decision_tree into master 2023-05-28 17:32:37 +02:00
3 changed files with 84 additions and 8 deletions
Showing only changes of commit 5339fbbe82 - Show all commits

View File

@ -1,13 +1,15 @@
import os
from trainingData import TrainingData
from sklearn import tree
import joblib
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
import numpy as np
def _read_training_data() -> TrainingData:
attributes: list[list[str]] = []
classes: list[str] = []
__location__ = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))
file = open(os.path.join(__location__, 'training_data.csv'))
attributes = []
classes = []
location = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
file = open(os.path.join(location, 'training_data.csv'))
lines = file.readlines()[1:]
file.close()
for line in lines:
@ -19,5 +21,29 @@ def _read_training_data() -> TrainingData:
classes.append(line_class)
return TrainingData(attributes, classes)
trainning_data = _read_training_data()
X = trainning_data.attributes
Y = trainning_data.classes
le_shape = LabelEncoder()
le_flexibility = LabelEncoder()
le_color = LabelEncoder()
le_shape.fit([x[0] for x in X])
le_flexibility.fit([x[3] for x in X])
le_color.fit([x[4] for x in X])
X_encoded = np.array([
[le_shape.transform([x[0]])[0], x[1], x[2], le_flexibility.transform([x[3]])[0], le_color.transform([x[4]])[0]]
for x in X
])
encoder = OneHotEncoder(categories='auto', sparse=False)
X_encoded = encoder.fit_transform(X_encoded)
model = tree.DecisionTreeClassifier()
model.fit(X_encoded, Y)
joblib.dump(model, 'model.pkl')

BIN
machine_learning/model.pkl Normal file

Binary file not shown.

View File

@ -98,4 +98,54 @@ Irregular,Medium,No,High,High,Dark,Low,Yes, PLASTIC_AND_METAL
Flat,High,Yes,Medium,Medium,Colorful,Low,Yes,PAPER
Longitiudonal,Low,Yes,Medium,Medium,Light,Medium,Yes,MIXED
Round,Medium,Yes,High,Low,Light,Medium,Yes,PLASTIC_AND_METAL
Longitiudonal,High,No,Medium,Low,Light,Low,Yes,PLASTIC_AND_METAL
Longitiudonal,High,No,Medium,Low,Light,Low,Yes,PLASTIC_AND_METAL
Flat,Low,Yes,Low,High,Light,Medium,Yes,PLASTIC_AND_METAL
Irregular,High,No,Low,High,Light,Low,No,PAPER
Round,High,Yes,High,Medium,Colorful,Low,No,MIXED
Flat,Low,Yes,Medium,Low,Transparent,Low,Yes,PLASTIC_AND_METAL
Irregular,Low,No,Medium,Low,Dark,Low,No,PAPER
Round,Low,No,Medium,Medium,Light,Medium,Yes,PLASTIC_AND_METAL
Longitiudonal,High,Yes,Low,Low,Light,High,No,MIXED
Irregular,Medium,Yes,Low,Medium,Light,High,No,MIXED
Flat,High,Yes,High,Medium,Dark,Low,No,PLASTIC_AND_METAL
Round,Low,Yes,Medium,Medium,Light,Medium,No,PLASTIC_AND_METAL
Round,Low,No,Low,Medium,Dark,Medium,No,PAPER
Irregular,Low,Yes,High,Low,Transparent,Medium,No,PLASTIC_AND_METAL
Longitiudonal,High,Yes,High,High,Transparent,Low,Yes,PLASTIC_AND_METAL
Round,High,Yes,Low,Medium,Transparent,Low,Yes,MIXED
Longitiudonal,High,Yes,Medium,Medium,Colorful,Low,Yes,MIXED
Round,Low,Yes,Low,Medium,Dark,Low,Yes,MIXED
Flat,Medium,No,Medium,High,Colorful,Low,No,PAPER
Irregular,High,Yes,Low,High,Transparent,Medium,No,BIO
Round,Medium,Yes,High,Medium,Transparent,High,Yes,MIXED
Flat,Low,No,Medium,Medium,Colorful,High,No,GLASS
Longitiudonal,Medium,No,High,Medium,Colorful,Medium,No,GLASS
Longitiudonal,Low,Yes,Low,Medium,Colorful,Medium,Yes,PLASTIC_AND_METAL
Irregular,Medium,No,Medium,High,Transparent,Medium,No,PAPER
Longitiudonal,Medium,Yes,Low,Medium,Dark,High,Yes,MIXED
Round,Low,Yes,High,High,Dark,Medium,No,MIXED
Longitiudonal,High,No,Low,High,Colorful,High,No,MIXED
Flat,Low,Yes,Medium,Medium,Transparent,High,Yes,PLASTIC_AND_METAL
Irregular,High,Yes,High,Medium,Light,High,No,PAPER
Longitiudonal,Low,Yes,High,Medium,Colorful,Low,Yes,PAPER
Round,Medium,No,High,Low,Colorful,High,No,PLASTIC_AND_METAL
Longitiudonal,High,No,Medium,Low,Dark,Medium,No,MIXED
Round,High,Yes,Medium,Medium,Light,Medium,No,GLASS
Longitiudonal,Low,No,Low,Medium,Light,Medium,No,MIXED
Longitiudonal,High,Yes,High,Low,Transparent,High,Yes,PLASTIC_AND_METAL
Round,Medium,Yes,Low,High,Light,High,No,PLASTIC_AND_METAL
Round,High,Yes,High,High,Light,Medium,Yes,MIXED
Flat,Low,No,Medium,High,Transparent,High,Yes,PAPER
Irregular,Medium,Yes,Low,High,Dark,High,Yes,PLASTIC_AND_METAL
Longitiudonal,Low,No,Low,Low,Transparent,High,No,MIXED
Round,High,No,Medium,High,Light,High,Yes,PAPER
Irregular,Low,No,Low,High,Light,Medium,Yes,MIXED
Irregular,High,No,Low,High,Light,High,No,PAPER
Longitiudonal,High,No,Low,Medium,Transparent,Low,No,PLASTIC_AND_METAL
Irregular,Low,Yes,High,Low,Colorful,Medium,No,MIXED
Round,Low,No,High,Low,Colorful,High,No,BIO
Irregular,Medium,No,High,High,Colorful,Low,Yes,BIO
Irregular,High,No,Medium,High,Colorful,Low,Yes,PAPER
Irregular,Low,No,Medium,Low,Dark,Medium,Yes,PLASTIC_AND_METAL
Longitiudonal,Medium,Yes,Low,Low,Light,High,Yes,MIXED
Flat,High,No,High,Low,Transparent,Low,No,PLASTIC_AND_METAL

1 Shape Flexibility DoesSmell Weight Size Color Softness DoesDin GarbageType
98 Flat High Yes Medium Medium Colorful Low Yes PAPER
99 Longitiudonal Low Yes Medium Medium Light Medium Yes MIXED
100 Round Medium Yes High Low Light Medium Yes PLASTIC_AND_METAL
101 Longitiudonal High No Medium Low Light Low Yes PLASTIC_AND_METAL
102 Flat Low Yes Low High Light Medium Yes PLASTIC_AND_METAL
103 Irregular High No Low High Light Low No PAPER
104 Round High Yes High Medium Colorful Low No MIXED
105 Flat Low Yes Medium Low Transparent Low Yes PLASTIC_AND_METAL
106 Irregular Low No Medium Low Dark Low No PAPER
107 Round Low No Medium Medium Light Medium Yes PLASTIC_AND_METAL
108 Longitiudonal High Yes Low Low Light High No MIXED
109 Irregular Medium Yes Low Medium Light High No MIXED
110 Flat High Yes High Medium Dark Low No PLASTIC_AND_METAL
111 Round Low Yes Medium Medium Light Medium No PLASTIC_AND_METAL
112 Round Low No Low Medium Dark Medium No PAPER
113 Irregular Low Yes High Low Transparent Medium No PLASTIC_AND_METAL
114 Longitiudonal High Yes High High Transparent Low Yes PLASTIC_AND_METAL
115 Round High Yes Low Medium Transparent Low Yes MIXED
116 Longitiudonal High Yes Medium Medium Colorful Low Yes MIXED
117 Round Low Yes Low Medium Dark Low Yes MIXED
118 Flat Medium No Medium High Colorful Low No PAPER
119 Irregular High Yes Low High Transparent Medium No BIO
120 Round Medium Yes High Medium Transparent High Yes MIXED
121 Flat Low No Medium Medium Colorful High No GLASS
122 Longitiudonal Medium No High Medium Colorful Medium No GLASS
123 Longitiudonal Low Yes Low Medium Colorful Medium Yes PLASTIC_AND_METAL
124 Irregular Medium No Medium High Transparent Medium No PAPER
125 Longitiudonal Medium Yes Low Medium Dark High Yes MIXED
126 Round Low Yes High High Dark Medium No MIXED
127 Longitiudonal High No Low High Colorful High No MIXED
128 Flat Low Yes Medium Medium Transparent High Yes PLASTIC_AND_METAL
129 Irregular High Yes High Medium Light High No PAPER
130 Longitiudonal Low Yes High Medium Colorful Low Yes PAPER
131 Round Medium No High Low Colorful High No PLASTIC_AND_METAL
132 Longitiudonal High No Medium Low Dark Medium No MIXED
133 Round High Yes Medium Medium Light Medium No GLASS
134 Longitiudonal Low No Low Medium Light Medium No MIXED
135 Longitiudonal High Yes High Low Transparent High Yes PLASTIC_AND_METAL
136 Round Medium Yes Low High Light High No PLASTIC_AND_METAL
137 Round High Yes High High Light Medium Yes MIXED
138 Flat Low No Medium High Transparent High Yes PAPER
139 Irregular Medium Yes Low High Dark High Yes PLASTIC_AND_METAL
140 Longitiudonal Low No Low Low Transparent High No MIXED
141 Round High No Medium High Light High Yes PAPER
142 Irregular Low No Low High Light Medium Yes MIXED
143 Irregular High No Low High Light High No PAPER
144 Longitiudonal High No Low Medium Transparent Low No PLASTIC_AND_METAL
145 Irregular Low Yes High Low Colorful Medium No MIXED
146 Round Low No High Low Colorful High No BIO
147 Irregular Medium No High High Colorful Low Yes BIO
148 Irregular High No Medium High Colorful Low Yes PAPER
149 Irregular Low No Medium Low Dark Medium Yes PLASTIC_AND_METAL
150 Longitiudonal Medium Yes Low Low Light High Yes MIXED
151 Flat High No High Low Transparent Low No PLASTIC_AND_METAL