“Klasifikasi Pohon Keputusan” Kode Jawaban

Klasifikasi Pohon Keputusan

# Import DecisionTreeClassifier from sklearn.tree
from sklearn.tree import DecisionTreeClassifier

# Instantiate a DecisionTreeClassifier 'dt' with a maximum depth of 6
dt = DecisionTreeClassifier(max_depth=6, criterion='entropy///gini', random_state=1)

# Fit dt to the training set
dt.fit(X_train, y_train)

# Predict test set labels
y_pred = dt.predict(X_test)
print(y_pred[0:5])
# Import accuracy_score
from sklearn.metrics import accuracy_score

# Compute test set accuracy  
acc = accuracy_score(y_test, y_pred)
print("Test set accuracy: {:.2f}".format(acc))
josh.ipynb

KEPUTUSAN BELAJAR SAMBUNG

from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import export_text
iris = load_iris()
decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)
decision_tree = decision_tree.fit(iris.data, iris.target)
r = export_text(decision_tree, feature_names=iris['feature_names'])
print(r)


Uninterested Unicorn

Contoh Klasifikasi Pohon Keputusan

# Create Decision Tree classifer object
clf = DecisionTreeClassifier()

# Train Decision Tree Classifer
clf = clf.fit(X_train,y_train)

#Predict the response for test dataset
y_pred = clf.predict(X_test)
Luis Magalhaes

KEPUTUSAN BELAJAR SAMBUNG

import graphviz 
dot_data = tree.export_graphviz(clf, out_file=None) 
graph = graphviz.Source(dot_data) 
graph.render("iris") 
Uninterested Unicorn

KEPUTUSAN BELAJAR SAMBUNG

from sklearn.datasets import load_iris
from sklearn import tree
X, y = load_iris(return_X_y=True)
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X, y)
Uninterested Unicorn

Jawaban yang mirip dengan “Klasifikasi Pohon Keputusan”

Pertanyaan yang mirip dengan “Klasifikasi Pohon Keputusan”

Lebih banyak jawaban terkait untuk “Klasifikasi Pohon Keputusan” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya