0% found this document useful (0 votes)
13 views2 pages

Python Lab10b

The document outlines a project aimed at predicting student exam outcomes based on study hours using Scikit-Learn and Logistic Regression. It includes a Python program that builds a machine learning model, trains it on sample data, and visualizes the results. The implementation successfully predicts outcomes and evaluates model accuracy.

Uploaded by

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

Python Lab10b

The document outlines a project aimed at predicting student exam outcomes based on study hours using Scikit-Learn and Logistic Regression. It includes a Python program that builds a machine learning model, trains it on sample data, and visualizes the results. The implementation successfully predicts outcomes and evaluates model accuracy.

Uploaded by

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

EX.

NO: 10 B)
71762305009 Scikit-Learn
26.03.2025

AIM:
To learn and implement python programs using Scikit -Learn and applying
Logistic Regression for Classification.

PROGRAM:
A school wants to predict whether students will pass or fail their final exams
based on the number of hours they study per week. They have collected data on
students' study hours and their final result (Pass = 1, Fail = 0). Your task is to
build a simple machine learning model using Scikit-Learn to make predictions.
CODE:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, confusion_matrix

data = {
"Study Hours": [1.5, 3.0, 4.5, 6.0, 7.5, 9.0, 10.5],
"Result": [0, 0, 0, 1, 1, 1, 1]
}

df = pd.DataFrame(data)

X = df[["Study Hours"]] # Input feature (study hours)


y = df["Result"] # Target variable (Pass = 1, Fail = 0)

model = LogisticRegression()
model.fit(X, y)

study_hours_test = [[5.0]] # Predict for 5 study hours


prediction = model.predict(study_hours_test)
print(f"Prediction for 5 study hours: {'Pass' if prediction[0] == 1 else 'Fail'}")

y_pred = model.predict(X)
accuracy = accuracy_score(y, y_pred)
print(f"Model Accuracy: {accuracy * 100:.2f}%")
cm = confusion_matrix(y, y_pred)
print("Confusion Matrix:\n", cm)
X_range = np.linspace(1, 11, 100).reshape(-1, 1) # Generating values for
visualization
y_prob = model.predict_proba(X_range)[:, 1] # Get probabilities
plt.scatter(X, y, color='blue', label="Actual Data")
plt.plot(X_range, y_prob, color='red', label="Logistic Regression Curve")
plt.xlabel("Study Hours")
plt.ylabel("Probability of Passing")
plt.title("Logistic Regression - Study Hours vs. Pass Probability")
plt.legend()
plt.show()
OUTPUT:

RESULT:
The python program using scikit-learn has been successfully implemented and
verified.

You might also like