Unverified Commit bd21efed authored by Nikita Titov's avatar Nikita Titov Committed by GitHub
Browse files

[python] Improving the syntax of `print`s in `simple_example.py` and `sklearn_example.py` (#4396)

* Update simple_example.py

* Update sklearn_example.py
parent 0ca2c494
...@@ -47,4 +47,5 @@ print('Starting predicting...') ...@@ -47,4 +47,5 @@ print('Starting predicting...')
# predict # predict
y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration) y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration)
# eval # 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}')
...@@ -30,10 +30,11 @@ print('Starting predicting...') ...@@ -30,10 +30,11 @@ print('Starting predicting...')
# predict # predict
y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration_) y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration_)
# eval # 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 # feature importances
print('Feature importances:', list(gbm.feature_importances_)) print(f'Feature importances: {list(gbm.feature_importances_)}')
# self-defined eval metric # self-defined eval metric
...@@ -69,8 +70,10 @@ print('Starting predicting...') ...@@ -69,8 +70,10 @@ print('Starting predicting...')
# predict # predict
y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration_) y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration_)
# eval # eval
print('The rmsle of prediction is:', rmsle(y_test, y_pred)[1]) rmsle_test = rmsle(y_test, y_pred)[1]
print('The rae of prediction is:', rae(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 # other scikit-learn modules
estimator = lgb.LGBMRegressor(num_leaves=31) estimator = lgb.LGBMRegressor(num_leaves=31)
...@@ -83,4 +86,4 @@ param_grid = { ...@@ -83,4 +86,4 @@ param_grid = {
gbm = GridSearchCV(estimator, param_grid, cv=3) gbm = GridSearchCV(estimator, param_grid, cv=3)
gbm.fit(X_train, y_train) 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_}')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment