Skip to content

Commit

Permalink
feat: random forest for s3e11 (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
TPLin22 authored Sep 26, 2024
1 parent ab55d70 commit b57846d
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pandas as pd
from sklearn.ensemble import RandomForestRegressor


def select(X: pd.DataFrame) -> pd.DataFrame:
# Ignore feature selection logic
return X


def fit(X_train: pd.DataFrame, y_train: pd.DataFrame, X_valid: pd.DataFrame, y_valid: pd.DataFrame):
"""Define and train the Random Forest model. Merge feature_select"""
X_train = select(X_train)

rf_params = {
"n_estimators": 100,
"max_depth": 10,
"min_samples_split": 2,
"min_samples_leaf": 1,
"max_features": "sqrt",
"random_state": 2023,
"n_jobs": -1,
"verbose": 1,
}
model = RandomForestRegressor(**rf_params)
model.fit(X_train, y_train)
return model


def predict(model, X_test):
"""
Keep feature select's consistency.
"""
X_test = select(X_test)
y_pred = model.predict(X_test)
return y_pred.reshape(-1, 1)

0 comments on commit b57846d

Please sign in to comment.