Untitled

 avatar
unknown
plain_text
a year ago
1.0 kB
2
Indexable
# Import necessary libraries
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score

# Sample dataset (replace this with your own dataset)
# X represents features, and y represents labels
X, y = [[0, 0], [1, 1], [0, 1], [1, 0]], [0, 1, 1, 0]

# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)

# Create a decision tree classifier
classifier = DecisionTreeClassifier()

# Train the classifier on the training data
classifier.fit(X_train, y_train)

# Make predictions on the test data
predictions = classifier.predict(X_test)

# Evaluate the accuracy of the model
accuracy = accuracy_score(y_test, predictions)
print(f"Accuracy: {accuracy}")

# Now you can use the trained model for making predictions on new data
new_data = [[1, 0]]
new_prediction = classifier.predict(new_data)
print(f"Prediction for new data: {new_prediction}")
Leave a Comment