Skip to content

Commit

Permalink
[python] Improving the syntax of prints in simple_example.py and …
Browse files Browse the repository at this point in the history
…`sklearn_example.py` (microsoft#4396)

* Update simple_example.py

* Update sklearn_example.py
  • Loading branch information
StrikerRUS authored Jun 22, 2021
1 parent 0ca2c49 commit bd21efe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion examples/python-guide/simple_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@
# predict
y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration)
# eval
print('The rmse of prediction is:', mean_squared_error(y_test, y_pred) ** 0.5)
rmse_test = mean_squared_error(y_test, y_pred) ** 0.5
print(f'The RMSE of prediction is: {rmse_test}')
13 changes: 8 additions & 5 deletions examples/python-guide/sklearn_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
# predict
y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration_)
# eval
print('The rmse of prediction is:', mean_squared_error(y_test, y_pred) ** 0.5)
rmse_test = mean_squared_error(y_test, y_pred) ** 0.5
print(f'The RMSE of prediction is: {rmse_test}')

# feature importances
print('Feature importances:', list(gbm.feature_importances_))
print(f'Feature importances: {list(gbm.feature_importances_)}')


# self-defined eval metric
Expand Down Expand Up @@ -69,8 +70,10 @@ def rae(y_true, y_pred):
# predict
y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration_)
# eval
print('The rmsle of prediction is:', rmsle(y_test, y_pred)[1])
print('The rae of prediction is:', rae(y_test, y_pred)[1])
rmsle_test = rmsle(y_test, y_pred)[1]
rae_test = rae(y_test, y_pred)[1]
print(f'The RMSLE of prediction is: {rmsle_test}')
print(f'The RAE of prediction is: {rae_test}')

# other scikit-learn modules
estimator = lgb.LGBMRegressor(num_leaves=31)
Expand All @@ -83,4 +86,4 @@ def rae(y_true, y_pred):
gbm = GridSearchCV(estimator, param_grid, cv=3)
gbm.fit(X_train, y_train)

print('Best parameters found by grid search are:', gbm.best_params_)
print(f'Best parameters found by grid search are: {gbm.best_params_}')

0 comments on commit bd21efe

Please sign in to comment.