決定木|Decision Tree Classifier pythonとsklearn

機械学習




決定木|Decision Tree Classifier

勉強中です。

sklearn DecisionTreeClassifier

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
X = load_iris().data
y = load_iris().target

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)

from sklearn.tree import DecisionTreeClassifier

tree = DecisionTreeClassifier(criterion='gini', max_depth=4, random_state=1)
tree.fit(X_train, y_train)
print(accuracy_score(tree.predict(X_test), y_test))
タイトルとURLをコピーしました