Decision tree test #1
This commit is contained in:
parent
ebc5cd61bd
commit
6126010db1
25
1.py
Normal file
25
1.py
Normal file
@ -0,0 +1,25 @@
|
||||
from sklearn.datasets import load_iris
|
||||
from sklearn.tree import DecisionTreeClassifier
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn import metrics
|
||||
|
||||
# Load the Iris dataset (or you can use your own dataset)
|
||||
iris = load_iris()
|
||||
X = iris.data
|
||||
y = iris.target
|
||||
|
||||
# Split the dataset into training and testing sets
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
||||
|
||||
# Create an instance of the DecisionTreeClassifier
|
||||
clf = DecisionTreeClassifier()
|
||||
|
||||
# Train the decision tree classifier
|
||||
clf.fit(X_train, y_train)
|
||||
|
||||
# Make predictions on the testing set
|
||||
y_pred = clf.predict(X_test)
|
||||
|
||||
# Evaluate the accuracy of the model
|
||||
accuracy = metrics.accuracy_score(y_test, y_pred)
|
||||
print("Accuracy:", accuracy)
|
Loading…
Reference in New Issue
Block a user