Last active
August 26, 2022 13:28
-
-
Save meir412/fc1fc016229ef8d327d6b1fd0963ed04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn import datasets | |
from sklearn.model_selection import train_test_split | |
from sklearn.metrics import mean_squared_error as mse | |
from sklearn.ensemble import RandomForestRegressor | |
from lightgbm import LGBMRegressor | |
X, y = datasets.load_diabetes(return_X_y=True) | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | |
rf_regressor = RandomForestRegressor(n_estimators=30) | |
rf_regressor.fit(X_train, y_train) | |
train_error = mse(y_train, rf_regressor.predict(X_train)) | |
test_error = mse(y_test, rf_regressor.predict(X_test)) | |
print('RF test error:', test_error) | |
print('RF overfit ratio:', test_error/train_error) | |
boosting_regressor = LGBMRegressor(n_estimators=30, learning_rate=0.12) | |
boosting_regressor.fit(X_train, y_train) | |
train_error = mse(y_train, boosting_regressor.predict(X_train)) | |
test_error = mse(y_test, boosting_regressor.predict(X_test)) | |
print('Boosting test error:', test_error) | |
print('Boosting overfit ratio:', test_error/train_error) | |
dart_regressor = LGBMRegressor(n_estimators=30, learning_rate=0.12, boosting_type='dart', skip_drop=0.7) | |
dart_regressor.fit(X_train, y_train) | |
train_error = mse(y_train, dart_regressor.predict(X_train)) | |
test_error = mse(y_test, dart_regressor.predict(X_test)) | |
print('Dart test error:', test_error) | |
print('Dart overfit ratio:', test_error/train_error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model | test_error | overfit_ratio | |
---|---|---|---|
RF | 3081.16 | 5.66 | |
Boosting | 2856.16 | 2.16 | |
Dart | 2756.31 | 1.77 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment