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

[python-package] use f-strings for concatenation in examples/python-guide/logistic_regression.py #4355

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 4 additions & 8 deletions examples/python-guide/logistic_regression.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# coding: utf-8
"""Comparison of `binary` and `xentropy` objectives.

BLUF: The `xentropy` objective does logistic regression and generalizes
to the case where labels are probabilistic (i.e. numbers between 0 and 1).

Details: Both `binary` and `xentropy` minimize the log loss and use
`boost_from_average = TRUE` by default. Possibly the only difference
between them with default settings is that `binary` may achieve a slight
Expand Down Expand Up @@ -54,7 +52,6 @@ def log_loss(preds, labels):

def experiment(objective, label_type, data):
"""Measure performance of an objective.

Parameters
----------
objective : string 'binary' or 'xentropy'
Expand All @@ -63,15 +60,14 @@ def experiment(objective, label_type, data):
Type of the label.
data : dict
Data for training.

Returns
-------
result : dict
Experiment summary stats.
"""
np.random.seed(0)
nrounds = 5
lgb_data = data['lgb_with_' + label_type + '_labels']
lgb_data = data[f"lgb_with_{label_type}_labels"]
params = {
'objective': objective,
'feature_fraction': 1,
Expand All @@ -81,7 +77,7 @@ def experiment(objective, label_type, data):
time_zero = time.time()
gbm = lgb.train(params, lgb_data, num_boost_round=nrounds)
y_fitted = gbm.predict(data['X'])
y_true = data[label_type + '_labels']
y_true = data[f"{label_type}_labels"]
duration = time.time() - time_zero
return {
'time': duration,
Expand Down Expand Up @@ -113,5 +109,5 @@ def experiment(objective, label_type, data):
for k in range(K)]
B = [experiment('xentropy', label_type='binary', data=DATA)['time']
for k in range(K)]
print('Best `binary` time: ' + str(min(A)))
print('Best `xentropy` time: ' + str(min(B)))
print(f"Best `binary` time: {str(min(A))}")
print(f"Best `xentropy` time: {str(min(B))}")