Unverified Commit 8e5079ef authored by Sagnik Roy's avatar Sagnik Roy Committed by GitHub
Browse files

[python-package] use f-strings for concatenation in...

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

* updated with f-string migration

* Update logistic_regression.py

* Update logistic_regression.py

* Update logistic_regression.py

* Update logistic_regression.py
parent bab58d0e
...@@ -71,7 +71,7 @@ def experiment(objective, label_type, data): ...@@ -71,7 +71,7 @@ def experiment(objective, label_type, data):
""" """
np.random.seed(0) np.random.seed(0)
nrounds = 5 nrounds = 5
lgb_data = data['lgb_with_' + label_type + '_labels'] lgb_data = data[f"lgb_with_{label_type}_labels"]
params = { params = {
'objective': objective, 'objective': objective,
'feature_fraction': 1, 'feature_fraction': 1,
...@@ -81,7 +81,7 @@ def experiment(objective, label_type, data): ...@@ -81,7 +81,7 @@ def experiment(objective, label_type, data):
time_zero = time.time() time_zero = time.time()
gbm = lgb.train(params, lgb_data, num_boost_round=nrounds) gbm = lgb.train(params, lgb_data, num_boost_round=nrounds)
y_fitted = gbm.predict(data['X']) y_fitted = gbm.predict(data['X'])
y_true = data[label_type + '_labels'] y_true = data[f"{label_type}_labels"]
duration = time.time() - time_zero duration = time.time() - time_zero
return { return {
'time': duration, 'time': duration,
...@@ -113,5 +113,5 @@ A = [experiment('binary', label_type='binary', data=DATA)['time'] ...@@ -113,5 +113,5 @@ A = [experiment('binary', label_type='binary', data=DATA)['time']
for k in range(K)] for k in range(K)]
B = [experiment('xentropy', label_type='binary', data=DATA)['time'] B = [experiment('xentropy', label_type='binary', data=DATA)['time']
for k in range(K)] for k in range(K)]
print('Best `binary` time: ' + str(min(A))) print(f"Best `binary` time: {min(A)}")
print('Best `xentropy` time: ' + str(min(B))) print(f"Best `xentropy` time: {min(B)}")
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