Avançar para o conteúdo principal

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


Comentários

Mensagens populares deste blogue

Let's make a car in Unity 3D

In this post we will make a simple car in Unity 3D. The Unity 3D physics engine is used in order to give the car a real behavior. This are the steps: [1] - Create a new Project

PacMan 3D

In this post we will be making a simple and classic game, the Pacman, with Unity 3D. Let's create a new a new project

Upgrading Windows 10 Home to Pro

 So I have been thinking about upgrading my Windows 10 Home Edition to the Pro version, but I always get to the point where it seems that I had to reinstall the entire SO and quit. After some investigating I have done it this way: - following this post  on the microsoft site I use one of the default keys for Windows 10 Pro and went to Settings > Update & Security > Activation > Change the product key; - next, Windows will activate the Pro functionalities and asks to restart; - now you have the Pro version but it's not activated, so you have to buy a Windows Pro Key. I went to UR cdkeys  and bought a key for less then €20; - and with the new key went to Change the product key and activated; - and it's done. Disclaimer : I have nothing to do with UR cdkeys so you can use any site to buy you cd key and your experience may vary from mine.