Skip to content

Commit

Permalink
Create Ml-Classification-Model.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Stalin-143 authored Dec 14, 2024
1 parent 6f5d347 commit c7b0a30
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Ml-Classification-Model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score, classification_report

# Load the Iris dataset
iris = load_iris()
X = iris.data # Features (sepal and petal measurements)
y = iris.target # Target (species)

# 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
classifier = DecisionTreeClassifier(random_state=42)

# Train the model
classifier.fit(X_train, y_train)

# Make predictions
y_pred = classifier.predict(X_test)

# Evaluate the model
accuracy = accuracy_score(y_test, y_pred)
print(f"Accuracy: {accuracy:.2f}")

# Classification report
print("\nClassification Report:")
print(classification_report(y_test, y_pred, target_names=iris.target_names))

# Optional: Predict a new sample
new_sample = np.array([[5.0, 3.5, 1.3, 0.3]]) # Example flower measurements
prediction = classifier.predict(new_sample)
print(f"\nPredicted class for new sample: {iris.target_names[prediction[0]]}")

0 comments on commit c7b0a30

Please sign in to comment.