Master LLMs with our FREE course in collaboration with Activeloop & Intel Disruptor Initiative. Join now!


Demystifying Decision Trees
Latest   Machine Learning

Demystifying Decision Trees

Last Updated on March 30, 2023 by Editorial Team

Author(s): Andrea Ianni

Originally published on Towards AI.

Explained from scratch, step by step

Some time ago, I found myself having to explain the tree-based algorithms to a person who was into mathematics… but with zero knowledge of data science. So, I decided to ignore the classic toy datasets and started completely from scratch, from a bunch of 2-dimensional points.

So, after some basic imports

import pandas as pdfrom sklearn import treeimport seaborn as sns

I drew 6 points on a sheet: 4 blue, and 2 orange:

X = [[0, 0], [1, 1], [2,1], [1,2], [2,2], [0.5, 1.5]]Y = [0, 1, 1, 1, 1, 0]example = pd.DataFrame(X)example["target"] = Ydisplay(example)colors = example["target"].map({0:"orange", 1:"blue"})sns.scatterplot(data=example, x=0, y=1, c=colors, s=200)

It is a… Read the full blog for free on Medium.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓