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

Single Page App with C# WPF/XAML

 In this post we are going to create a single page app. The app will have multiple pages that get rendered in the main window. We will be using Visual Studio, C#, WPF and XAML. Let's start by creating a new project in Visual Studio of this type: Next, in the MainWindow, we define the interface structure. On the left side we place a menu and on the right side a DockPanel with a Frame in it. The Frame is the element that is used to render de pages content. Now let's add the new pages. In this example I will add two pages. Click in the Solution Explorer with the mouse right button, then choose Add and Page. The project looks like this. The app content goes on the recently create pages. Because this is just an example I will just change the background color and add a small text. Page1 Page2 Finally the code. Back to the MainWindow we need to create the click events on the menu items. So, in the MenuItem line add the click event and pick New Event Handler. If that option doesn't