# train_rf.py import pandas as pd from sklearn.ensemble import RandomForestRegressor from sklearn.model_selection import train_test_split import joblib import os # Sample dataset X = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]] y = [35, 45, 55, 65, 75, 80, 82, 88, 92, 95] # Convert to DataFrame df = pd.DataFrame(X, columns=['Hours']) df['Score'] = y # Split data X_train, X_test, y_train, y_test = train_test_split(df[['Hours']], df['Score'], test_size=0.2, random_state=42) # Train model model = RandomForestRegressor(n_estimators=100, random_state=42) model.fit(X_train, y_train) # Save the model os.makedirs('Models', exist_ok=True) joblib.dump(model, 'Models/rf_model.pkl') print("✅ Random Forest Regressor trained and saved.")