Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: random forest for s3e11 #347

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading