Files changed (1) hide show
  1. app.py +15 -46
app.py CHANGED
@@ -1,56 +1,25 @@
1
  import pandas as pd
2
- import gradio as gr
3
  from sklearn.model_selection import train_test_split
4
  from sklearn.ensemble import RandomForestRegressor
5
- import joblib
6
- import os
7
 
8
- # --- Load Dataset ---
9
- # Make sure you upload your CSV into the Space with the same name
10
- df = pd.read_csv("course_history_cleaned.csv")
 
11
 
12
- # Convert True/False into integers for modeling
13
- df["AP"] = df["AP"].astype(int)
14
- df["Honors"] = df["Honors"].astype(int)
15
 
16
- # --- Features & Target ---
17
- X = df[["AP", "Honors", "Credits_Attempted", "Credits_Earned"]]
18
- y = df["Weighted_GPA_Points"]
19
 
20
- # Train-test split
21
- X_train, X_test, y_train, y_test = train_test_split(
22
- X, y, test_size=0.2, random_state=42
23
- )
24
-
25
- # --- Train Model (Random Forest as best baseline) ---
26
  model = RandomForestRegressor(n_estimators=100, random_state=42)
27
  model.fit(X_train, y_train)
28
 
29
- # Save model for persistence
30
- joblib.dump(model, "gpa_model.pkl")
31
-
32
- # Reload model (useful when restarting Space)
33
- model = joblib.load("gpa_model.pkl")
34
-
35
- # --- Prediction Function ---
36
- def predict(ap, honors, credits_attempted, credits_earned):
37
- features = [[int(ap), int(honors), float(credits_attempted), float(credits_earned)]]
38
- prediction = model.predict(features)[0]
39
- return round(prediction, 2)
40
-
41
- # --- Gradio UI ---
42
- demo = gr.Interface(
43
- fn=predict,
44
- inputs=[
45
- gr.Checkbox(label="AP"),
46
- gr.Checkbox(label="Honors"),
47
- gr.Number(label="Credits Attempted"),
48
- gr.Number(label="Credits Earned")
49
- ],
50
- outputs=gr.Number(label="Predicted GPA Points"),
51
- title="GPA Prediction Model",
52
- description="Enter course details to predict GPA points (weighted)."
53
- )
54
-
55
- if __name__ == "__main__":
56
- demo.launch()
 
1
  import pandas as pd
 
2
  from sklearn.model_selection import train_test_split
3
  from sklearn.ensemble import RandomForestRegressor
4
+ from sklearn.metrics import r2_score
 
5
 
6
+ # ----------------------------
7
+ # Load dataset
8
+ CSV_PATH = "test_score_prediction_dataset.csv"
9
+ df = pd.read_csv(CSV_PATH)
10
 
11
+ # Features and target
12
+ X = df[["AP", "Honors", "GPA_Points", "Credits_Earned"]]
13
+ y = df["Predicted_Test_Score"]
14
 
15
+ # Train/test split
16
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
 
17
 
18
+ # ----------------------------
19
+ # Train model (Random Forest)
 
 
 
 
20
  model = RandomForestRegressor(n_estimators=100, random_state=42)
21
  model.fit(X_train, y_train)
22
 
23
+ # Predict and evaluate
24
+ y_pred = model.predict(X_test)
25
+ print("R² Score:", r2_score(y_test, y_pred))