# Step 0 / Cell 0
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report, r2_score, mean_squared_error
# Step 1: Load the Iris dataset
print("π₯ Loading the Iris dataset...")
data = load_iris()
# Step 2: Explore the dataset structure
print("\nπ Feature names:", data.feature_names)
print("π― Target classes:", data.target_names)
print("π Data shape:", data.data.shape)
# Step 3: Create a DataFrame for exploration
df = pd.DataFrame(data.data, columns=data.feature_names)
df['target'] = data.target
print("\nπ First 5 rows of the dataset:")
print(df.head())
# Step 4: Define features (X) and target (y)
X = df[data.feature_names]
y = df['target']
# Step 5: Train a Logistic Regression model
print("\nβοΈ Training Logistic Regression model...")
model = LogisticRegression(max_iter=200)
model.fit(X, y)
# Step 6: Make predictions
y_pred = model.predict(X)
# Step 7: Evaluate the model
accuracy = accuracy_score(y, y_pred)
print(f"\nπ Accuracy Score: {accuracy:.2f}")
print("\nπ Classification Report:")
print(classification_report(y, y_pred, target_names=data.target_names))
# Step 8 : Confusion Matrix Plot
cm = confusion_matrix(y, y_pred)
plt.figure(figsize=(6, 4))
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues',
xticklabels=data.target_names,
yticklabels=data.target_names)
plt.xlabel("Predicted")
plt.ylabel("Actual")
plt.title("π Confusion Matrix")
plt.show()
Last active
May 26, 2025 09:37
-
-
Save initcron/ab926bb37af1008a84fe7575fb57fe32 to your computer and use it in GitHub Desktop.
Sample Notebook Code
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment