JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Untitled Page | JustPaste.app
about 1 month ago0 views
👨‍💻Programming
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 LinearRegression
from sklearn.metrics import mean_absolute_error, mean_squared_error

data = {
    'Hours_Studied': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    'Test_Score': [10, 20, 30, 40, 50, 60, 70, 75, 85, 95]
}

df = pd.DataFrame(data)

print(df.head())

X = df[['Hours_Studied']] 
y = df['Test_Score']       

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

print(f"Training Data: {len(X_train)} rows")  
print(f"Testing Data: {len(X_test)} rows")

model = LinearRegression()

model.fit(X_train, y_train)

y_pred = model.predict(X_test)

df_results = pd.DataFrame({'Actual': y_test, 'Predicted': y_pred})
print(df_results)

mae = mean_absolute_error(y_test, y_pred)  
mse = mean_squared_error(y_test, y_pred)   
rmse = np.sqrt(mse)  

print(f"Mean Absolute Error (MAE): {mae}")
print(f"Mean Squared Error (MSE): {mse}")
print(f"Root Mean Squared Error (RMSE): {rmse}")

← Back to timeline