Untitled

Anonymous
plain_text
09/28/2026 6:08 AM
1.6 KB
14
Indexable
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report

# Load dataset
df = pd.read_csv("iris.csv")

# Select only two classes
df = df[df["variety"].isin(["Setosa", "Versicolor"])]

# Input features
X = df[[
    "sepal.length",
    "sepal.width",
    "petal.length",
    "petal.width"
]]

# Target variable
y = df["variety"]

# Split dataset into training and testing
X_train, X_test, y_train, y_test = train_test_split(
    X, y,
    test_size=0.2,
    random_state=42
)

# Create Logistic Regression model
model = LogisticRegression()

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

# Predict test data
y_pred = model.predict(X_test)

# Display results
print("Actual values:")
print(y_test.values)

print("\nPredicted values:")
print(y_pred)

# Accuracy
print("\nAccuracy:")
print(accuracy_score(y_test, y_pred))

# Confusion Matrix
print("\nConfusion Matrix:")
print(confusion_matrix(y_test, y_pred))

# Classification Report
print("\nClassification Report:")
print(classification_report(y_test, y_pred))
Editor is loading...
Leave a Comment