Spaces:
Sleeping
Sleeping
| import pandas as pd | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.ensemble import RandomForestRegressor | |
| from sklearn.metrics import r2_score | |
| # ---------------------------- | |
| # Load dataset | |
| CSV_PATH = "test_score_prediction_dataset.csv" | |
| df = pd.read_csv(CSV_PATH) | |
| # Features and target | |
| X = df[["AP", "Honors", "GPA_Points", "Credits_Earned"]] | |
| y = df["Predicted_Test_Score"] | |
| # Train/test split | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | |
| # ---------------------------- | |
| # Train model (Random Forest) | |
| model = RandomForestRegressor(n_estimators=100, random_state=42) | |
| model.fit(X_train, y_train) | |
| # Predict and evaluate | |
| y_pred = model.predict(X_test) | |
| print("R² Score:", r2_score(y_test, y_pred)) | |