diff --git a/examples/python-guide/advanced_example.py b/examples/python-guide/advanced_example.py index 2a4d2d3c923a..1fd8a9e94333 100644 --- a/examples/python-guide/advanced_example.py +++ b/examples/python-guide/advanced_example.py @@ -43,7 +43,7 @@ } # generate feature names -feature_name = ['feature_' + str(col) for col in range(num_feature)] +feature_name = [f'feature_{col}' for col in range(num_feature)] print('Starting training...') # feature_name and categorical_feature @@ -56,7 +56,7 @@ print('Finished first 10 rounds...') # check feature name -print('7th feature name is:', lgb_train.feature_name[6]) +print(f'7th feature name is: {lgb_train.feature_name[6]}') print('Saving model...') # save model to file @@ -70,10 +70,10 @@ json.dump(model_json, f, indent=4) # feature names -print('Feature names:', gbm.feature_name()) +print(f'Feature names: {gbm.feature_name()}') # feature importances -print('Feature importances:', list(gbm.feature_importance())) +print(f'Feature importances: {list(gbm.feature_importance())}') print('Loading model to predict...') # load model to predict @@ -81,7 +81,8 @@ # can only predict with the best iteration (or the saving iteration) y_pred = bst.predict(X_test) # eval with loaded model -print("The rmse of loaded model's prediction is:", mean_squared_error(y_test, y_pred) ** 0.5) +rmse_loaded_model = mean_squared_error(y_test, y_pred) ** 0.5 +print(f"The RMSE of loaded model's prediction is: {rmse_loaded_model}") print('Dumping and loading model with pickle...') # dump model with pickle @@ -93,7 +94,8 @@ # can predict with any iteration when loaded in pickle way y_pred = pkl_bst.predict(X_test, num_iteration=7) # eval with loaded model -print("The RMSE of pickled model's prediction is:", mean_squared_error(y_test, y_pred) ** 0.5) +rmse_pickled_model = mean_squared_error(y_test, y_pred) ** 0.5 +print(f"The RMSE of pickled model's prediction is: {rmse_pickled_model}") # continue training # init_model accepts: @@ -187,8 +189,7 @@ def accuracy(preds, train_data): feval=[binary_error, accuracy], valid_sets=lgb_eval) -print('Finished 50 - 60 rounds with self-defined objective function ' - 'and multiple self-defined eval metrics...') +print('Finished 50 - 60 rounds with self-defined objective function and multiple self-defined eval metrics...') print('Starting a new training job...')