0% found this document useful (0 votes)
10 views1 page

Ass1 SetB2

The document outlines a Python script that utilizes the Iris dataset for logistic regression analysis. It includes loading the dataset, converting it to a pandas DataFrame, printing statistical details for each species, splitting the data into training and testing sets, fitting a logistic regression model, and calculating the model's accuracy. The final output displays the accuracy of the predictions made on the test set.

Uploaded by

ashwinpunmagr99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Ass1 SetB2

The document outlines a Python script that utilizes the Iris dataset for logistic regression analysis. It includes loading the dataset, converting it to a pandas DataFrame, printing statistical details for each species, splitting the data into training and testing sets, fitting a logistic regression model, and calculating the model's accuracy. The final output displays the accuracy of the predictions made on the test set.

Uploaded by

ashwinpunmagr99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import pandas as pd

from sklearn.datasets import load_iris


from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

# Load the iris dataset


iris = load_iris()

# Convert to pandas dataframe


df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
df['target'] = iris.target

# Print basic statistical details of different species


print('Iris-setosa statistics:')
print(df[df['target'] == 0].describe())
print('Iris-versicolor statistics:')
print(df[df['target'] == 1].describe())
print('Iris-virginica statistics:')
print(df[df['target'] == 2].describe())

# Split data into train and test sets


X_train, X_test, y_train, y_test =
train_test_split(df[iris.feature_names], df['target'],
test_size=0.2,random_state=42)

# Fit logistic regression model


lr_model = LogisticRegression(random_state=42)
lr_model.fit(X_train, y_train)

# Predict on test set


y_pred = lr_model.predict(X_test)

# Calculate accuracy
accuracy = accuracy_score(y_test, y_pred)
print('Accuracy:', accuracy)

You might also like