Did It Work?

It’s time to check how well the classifier did. You can measure the performance of classifiers in various ways. You can find the accuracy by calculating the percentage correctly classified. For numeric data, you can use an error function, such as the mean squared error (MSE) which finds the average of the squares of the errors or difference between the predicted and actual values. For each problem, you need to decide how to test your algorithm.

How well has your decision tree performed? Try it on the four coordinates:

 data = [[0, 0, False], [1, 0, False], [0, 1, True], [1, 1, True]]
 label = [​'x'​, ​'y'​, ​'out'​]
 
 tree = create_tree(data, label)
 print​(as_rule_str(tree, label))

You get this rule:

 if y = 0 then False. ...

Get Genetic Algorithms and Machine Learning for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.