sexta-feira, 26 de janeiro de 2018

Decision Trees


In this article we create a decision tree to classify the gender of people based on their height, weight and size of footwear.


To begin we import from the tree from framework sklearn.


from sklearn import tree


Then we create a vector X with the values ​​that allow us to create a trend.


X=[[181,80,44],[177,70,43],[160,60,38],[154,54,37],[166,65,40],[190,90,47],[175,64,39],[177,70,40],[159,55,37],[171,75,42],[181,85,43]]


To these values ​​we have to join the classification of each element, so we created the vector Y.


Y=['male','female','female','female','male','male','male','female','male','female','male']


Now we can create an object of type DecisionTreeClassifier.

clf=tree.DecisionTreeClassifier()


We enter values ​​and ratings.

clf=clf.fit(X,Y)

Finally we can make a prediction based on a new example.

prediction=clf.predict([[160,50,33]])
print(prediction)

Just change the values ​​to get a different rating.


Code on Github


Video on YouTube


Sem comentários:

Enviar um comentário