Decision Trees - VisuallyExplained
Автор: Visually Explained
Загружено: 2025-03-30
Просмотров: 11112
Introduction to Decision Trees For Classification Problems with a Python Example.
#decisiontree #python #classification #datascience #statistics
Code snippets used in the video:
```
Install required packages
pip install pandas scikit-learn
Download Pokemon dataset
wget -q https://gist.githubusercontent.com/ar...\
194bcff35001e7eb53a2a8b441e8b2c6/raw/\
92200bc0a673d5ce2110aaad4544ed6c4010f687/pokemon.csv
Load dataset
import pandas as pd
df = pd.read_csv("pokemon.csv").rename(columns={"Type 1": "Type"})
Filter two types only
data = data.query("Type.isin(('Electric', 'Grass'))")
Training Dataset
X = data[['HP', 'Attack', 'Defense', 'Speed', ]] # Features
y = (data['Type'] == 'Electric') # = 0 if Grass, = 1 if Electric
Train decision tree
from sklearn.tree import DecisionTreeClassifier
tree = DecisionTreeClassifier(max_depth=1).fit(X, y)
Plot decision tree
from sklearn.tree import plot_tree
plot_tree(tree);
Predict using the decision tree
predictions = tree.predict(X)
predictions[3] # is Pokemon at index 3 of type "Electric"?
Accuracy score
from sklearn.metrics import accuracy_score
accuracy_score(y, tree.predict(X))
change depth to 2
tree = DecisionTreeClassifier(max_depth=2).fit(X, y)
```
--------------------------
This video would not have been possible without the help of Gökçe Dayanıklı.
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: