From 6126010db153663559d814964b938baae323e39a Mon Sep 17 00:00:00 2001 From: Mirrowel Date: Thu, 18 May 2023 19:17:24 +0200 Subject: [PATCH] Decision tree test #1 --- 1.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 1.py diff --git a/1.py b/1.py new file mode 100644 index 0000000..eecf7d7 --- /dev/null +++ b/1.py @@ -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) \ No newline at end of file