Last active
May 26, 2025 09:37
Revisions
-
initcron renamed this gist
May 26, 2025 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ ``` # Step 0 / Cell 0 import pandas as pd import numpy as np @@ -50,4 +51,6 @@ sns.heatmap(cm, annot=True, fmt='d', cmap='Blues', plt.xlabel("Predicted") plt.ylabel("Actual") plt.title("π Confusion Matrix") plt.show() ``` -
initcron created this gist
May 26, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ # 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()