Code:
# Import necessary libraries
from [Link] import load_iris
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from [Link] import classification_report, confusion_matrix, accuracy_score
# Load the Iris dataset
iris = load_iris()
X, y = [Link], [Link]
# Split the dataset into a 70-30 ratio for training and testing
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
random_state=42)
# Initialize and train the Logistic Regression model
model = LogisticRegression(max_iter=200)
[Link](X_train, y_train)
# Make predictions on the test set
y_pred = [Link](X_test)
# Evaluate the model's performance
accuracy = accuracy_score(y_test, y_pred)
conf_matrix = confusion_matrix(y_test, y_pred)
report = classification_report(y_test, y_pred, target_names=iris.target_names)
# Print the results
print("Accuracy: {:.2f}%".format(accuracy * 100))
print("\nConfusion Matrix:\n", conf_matrix)
print("\nClassification Report:\n", report)
import [Link] as plt
import seaborn as sns
# Class labels for Iris dataset
class_names = iris.target_names
# Plot the confusion matrix
[Link](figsize=(8, 6))
[Link](conf_matrix, annot=True, fmt="d", cmap="Blues",
xticklabels=class_names, yticklabels=class_names)
[Link]("Confusion Matrix")
[Link]("Predicted Label")
[Link]("True Label")
[Link]()
Output:
Accuracy: 100.00%
Confusion Matrix:
[[19 0 0]
[ 0 13 0]
[ 0 0 13]]
Classification Report:
precision recall f1-score support
setosa 1.00 1.00 1.00 19
versicolor 1.00 1.00 1.00 13
virginica 1.00 1.00 1.00 13
accuracy 1.00 45
macro avg 1.00 1.00 1.00 45
weighted avg 1.00 1.00 1.00 45