Files
FYS-STK4155/doc/src/DecisionTrees/moons.py
T
2019-10-27 21:13:33 +01:00

29 lines
692 B
Python

# Common imports
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import make_moons
from sklearn.tree import export_graphviz
from pydot import graph_from_dot_data
import pandas as pd
np.random.seed(42)
X, y = make_moons(n_samples=100, noise=0.25, random_state=53)
X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=0)
tree_clf = DecisionTreeClassifier(max_depth=5)
tree_clf.fit(X_train, y_train)
export_graphviz(
tree_clf,
out_file="moons.dot",
# feature_names=tree_clf.feature_names,
# class_names=tree_clf.target_names,
rounded=True,
filled=True
)