Example: Training your Model

We've decided that we're making a decision tree. Let's use sklearn to do this!

Let's first import sklearn:

from sklearn.tree import DecisionTreeClassifier

Awesome! Let's now load our data into training and testing data:

creditScoreAndIncomeTrain = [

approvedTrain = [

creditScoreAndIncomeTest = [

approvedTest = [

Note that normally we would have way more data than this (ideally loaded from a file or database), but this is enough for the tutorial! :)

Now let's build our decision tree. Sklearn does all of the heavy lifting for us. If we wanted to write custom code to build the tree we could look at an existing algorithm such as C4.5.

tree = DecisionTreeClassifier().fit(creditScoreAndIncomeTrain, approvedTrain)

Awesome! We have now built our tree; we just need to test it! Continue to the next page to see how to test it.

results matching ""

    No results matching ""