# Simple Linear Regression Example — Predict Exam Score from Hours Studied import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression # Step 1: Load dataset from online CSV url = "https://raw.githubusercontent.com/pranavshinde36/Student-Study-Hours-vs-Exam-Scores/main/Student_Score.csv" data = pd.read_csv(url) # Step 2: Prepare data X = data[['Hours']] # input feature y = data['Scores'] # output / target # Step 3: Create and train the model model = LinearRegression() model.fit(X, y) # Step 4: Print model parameters print(f"Slope (m): {model.coef_[0]:.2f}") print(f"Intercept (b): {model.intercept_:.2f}") # Step 5: Make predictions data['Predicted_Score'] = model.predict(X) # Step 6: Plot original data and regression line plt.scatter(X, y, color='blue', label='Actual Scores') plt.plot(X, data['Predicted_Score'], color='red', label='Regression Line') plt.xlabel('Hours Studied') plt.ylabel('Exam Score') plt.title('Hours vs Exam Score') plt.legend() plt.show() # Step 7: Predict score for new study hours new_hours = [[5], [8]] predicted_scores = model.predict(new_hours) for hours, score in zip(new_hours, predicted_scores): print(f"Predicted score for studying {hours[0]} hours: {score:.2f}") __ __