File size: 1,055 Bytes
a1af789
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error, r2_score

# Load your dataset
df = pd.read_excel("Book 1 (1).xlsx")

# Select features (X) and target (y)
# You can adjust this list depending on what you want to use
features = ["Attendance", "Hours studied", "Quizzes_avg", "Confidence"]
X = df[features]
y = df["Final Grade"]

# Split data into train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train a regression model
model = LinearRegression()
model.fit(X_train, y_train)

# Make predictions
y_pred = model.predict(X_test)

# Evaluate
print("Mean Absolute Error:", mean_absolute_error(y_test, y_pred))
print("R² Score:", r2_score(y_test, y_pred))

# Example: predict grade for a new student
sample = pd.DataFrame([{
    "Attendance": 0.95,
    "Hours studied": 12,
    "Quizzes_avg": 85,
    "Confidence": 7
}])
print("Predicted grade:", model.predict(sample)[0])