# Import necessary libraries
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score, classification_report
from sklearn.datasets import fetch_openml

# Load the MNIST Fashion dataset using scikit-learn's built-in datasets
fashion_mnist = fetch_openml(name="Fashion-MNIST", as_frame=False)

# Split the dataset into features (X) and labels (y)
X = fashion_mnist.data.astype('float32') / 255.0  # Normalize pixel values to [0, 1]
y = fashion_mnist.target.astype('int')

# 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)

# Initialize the Decision Tree classifier
decision_tree_classifier = DecisionTreeClassifier(random_state=42)
# Train the classifier
decision_tree_classifier.fit(X_train, y_train)
# Make predictions on the test set
y_pred = decision_tree_classifier.predict(X_test)

# Evaluate the classifier
accuracy = accuracy_score(y_test, y_pred)
print(f"Accuracy: {accuracy:.4f}")

# Print classification report
print("Classification Report:")
print(classification_report(y_test, y_pred))
