8000 MNT `ruff format` · scikit-learn/scikit-learn@b87f48e · GitHub
[go: up one dir, main page]

Skip to content

Commit b87f48e

Browse files
MNT ruff format
1 parent b5415eb commit b87f48e

File tree

59 files changed

+228
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+228
-235
lines changed

benchmarks/bench_hist_gradient_boosting_adult.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def predict(est, data_test, target_test):
4646
toc = time()
4747
roc_auc = roc_auc_score(target_test, predicted_proba_test[:, 1])
4848
acc = accuracy_score(target_test, predicted_test)
49-
print(f"predicted in {toc - tic:.3f}s, ROC AUC: {roc_auc:.4f}, ACC: {acc :.4f}")
49+
print(f"predicted in {toc - tic:.3f}s, ROC AUC: {roc_auc:.4f}, ACC: {acc:.4f}")
5050

5151

5252
data = fetch_openml(data_id=179, as_frame=True) # adult dataset

benchmarks/bench_hist_gradient_boosting_higgsboson.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def predict(est, data_test, target_test):
7474
toc = time()
7575
roc_auc = roc_auc_score(target_test, predicted_proba_test[:, 1])
7676
acc = accuracy_score(target_test, predicted_test)
77-
print(f"predicted in {toc - tic:.3f}s, ROC AUC: {roc_auc:.4f}, ACC: {acc :.4f}")
77+
print(f"predicted in {toc - tic:.3f}s, ROC AUC: {roc_auc:.4f}, ACC: {acc:.4f}")
7878

7979

8080
df = load_data()

examples/applications/plot_species_distribution_modeling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def create_species_bunch(species_name, train, test, coverages, xgrid, ygrid):
109109

110110

111111
def plot_species_distribution(
112-
species=("bradypus_variegatus_0", "microryzomys_minutus_0")
112+
species=("bradypus_variegatus_0", "microryzomys_minutus_0"),
113113
):
114114
"""
115115
Plot the species distribution.

examples/applications/plot_time_series_lagged_features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def consolidate_scores(cv_results, scores, metric):
265265
time = cv_results["fit_time"]
266266
scores["fit_time"].append(f"{time.mean():.2f} ± {time.std():.2f} s")
267267

268-
scores["loss"].append(f"quantile {int(quantile*100)}")
268+
scores["loss"].append(f"quantile {int(quantile * 100)}")
269269
for key, value in cv_results.items():
270270
if key.startswith("test_"):
271271
metric = key.split("test_")[1]

examples/applications/plot_topics_extraction_with_nmf_lda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def plot_top_words(model, feature_names, n_top_words, title):
5050

5151
ax = axes[topic_idx]
5252
ax.barh(top_features, weights, height=0.7)
53-
ax.set_title(f"Topic {topic_idx +1}", fontdict={"fontsize": 30})
53+
ax.set_title(f"Topic {topic_idx + 1}", fontdict={"fontsize": 30})
5454
ax.tick_params(axis="both", which="major", labelsize=20)
5555
for i in "top right left".split():
5656
ax.spines[i].set_visible(False)

examples/ensemble/plot_bias_variance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ def generate(n_samples, noise, n_repeat=1):
177177

178178
plt.subplot(2, n_estimators, n_estimators + n + 1)
179179
plt.plot(X_test, y_error, "r", label="$error(x)$")
180-
plt.plot(X_test, y_bias, "b", label="$bias^2(x)$"),
181-
plt.plot(X_test, y_var, "g", label="$variance(x)$"),
180+
(plt.plot(X_test, y_bias, "b", label="$bias^2(x)$"),)
181+
(plt.plot(X_test, y_var, "g", label="$variance(x)$"),)
182182
plt.plot(X_test, y_noise, "c", label="$noise(x)$")
183183

184184
plt.xlim([-5, 5])

examples/linear_model/plot_tweedie_regression_insurance_claims.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,9 @@ def score_estimator(
606606
"predicted, frequency*severity model": np.sum(
607607
exposure * glm_freq.predict(X) * glm_sev.predict(X)
608608
),
609-
"predicted, tweedie, power=%.2f"
610-
% glm_pure_premium.power: np.sum(exposure * glm_pure_premium.predict(X)),
609+
"predicted, tweedie, power=%.2f" % glm_pure_premium.power: np.sum(
610+
exposure * glm_pure_premium.predict(X)
611+
),
611612
}
612613
)
613614

examples/manifold/plot_lle_digits.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# Authors: The scikit-learn developers
1111
# SPDX-License-Identifier: BSD-3-Clause
1212

13-
1413
# %%
1514
# Load digits dataset
1615
# -------------------

examples/manifold/plot_manifold_sphere.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
t = random_state.rand(n_samples) * np.pi
5151

5252
# Sever the poles from the sphere.
53-
indices = (t < (np.pi - (np.pi / 8))) & (t > ((np.pi / 8)))
53+
indices = (t < (np.pi - (np.pi / 8))) & (t > (np.pi / 8))
5454
colors = p[indices]
5555
x, y, z = (
5656
np.sin(t[indices]) * np.cos(p[indices]),

examples/model_selection/plot_likelihood_ratios.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class proportion than the target application.
4040
from sklearn.datasets import make_classification
4141

4242
X, y = make_classification(n_samples=10_000, weights=[0.9, 0.1], random_state=0)
43-
print(f"Percentage of people carrying the disease: {100*y.mean():.2f}%")
43+
print(f"Percentage of people carrying the disease: {100 * y.mean():.2f}%")
4444

4545
# %%
4646
# A machine learning model is built to diagnose if a person with some given

examples/model_selection/plot_roc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@
152152
#
153153
# We can briefly demo the effect of :func:`numpy.ravel`:
154154

155-
print(f"y_score:\n{y_score[0:2,:]}")
155+
print(f"y_score:\n{y_score[0:2, :]}")
156156
print()
157-
print(f"y_score.ravel():\n{y_score[0:2,:].ravel()}")
157+
print(f"y_score.ravel():\n{y_score[0:2, :].ravel()}")
158158

159159
# %%
160160
# In a multi-class classification setup with highly imbalanced classes,
@@ -359,7 +359,7 @@
359359
plt.plot(
360360
fpr_grid,
361361
mean_tpr[ix],
362-
label=f"Mean {label_a} vs {label_b} (AUC = {mean_score :.2f})",
362+
label=f"Mean {label_a} vs {label_b} (AUC = {mean_score:.2f})",
363363
linestyle=":",
364364
linewidth=4,
365365
)

sklearn/_loss/tests/test_loss.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ def test_loss_boundary_y_true(loss, y_true_success, y_true_fail):
215215

216216

217217
@pytest.mark.parametrize(
218-
"loss, y_pred_success, y_pred_fail", Y_COMMON_PARAMS + Y_PRED_PARAMS # type: ignore
218+
"loss, y_pred_success, y_pred_fail",
219+
Y_COMMON_PARAMS + Y_PRED_PARAMS, # type: ignore
219220
)
220221
def test_loss_boundary_y_pred(loss, y_pred_success, y_pred_fail):
221222
"""Test boundaries of y_pred for loss functions."""
@@ -501,12 +502,14 @@ def test_loss_same_as_C_functions(loss, sample_weight):
501502
sample_weight=sample_weight,
502503
loss_out=out_l1,
503504
)
504-
loss.closs.loss(
505-
y_true=y_true,
506-
raw_prediction=raw_prediction,
507-
sample_weight=sample_weight,
508-
loss_out=out_l2,
509-
),
505+
(
506+
loss.closs.loss(
507+
y_true=y_true,
508+
raw_prediction=raw_prediction,
509+
sample_weight=sample_weight,
510+
loss_out=out_l2,
511+
),
512+
)
510513
assert_allclose(out_l1, out_l2)
511514
loss.gradient(
512515
y_true=y_true,

sklearn/cluster/_feature_agglomeration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# Authors: The scikit-learn developers
77
# SPDX-License-Identifier: BSD-3-Clause
88

9-
109
import numpy as np
1110
from scipy.sparse import issparse
1211

sklearn/cross_decomposition/tests/test_pls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,12 @@ def test_copy(Est):
404404

405405
X_orig = X.copy()
406406
with pytest.raises(AssertionError):
407-
pls.transform(X, Y, copy=False),
407+
(pls.transform(X, Y, copy=False),)
408408
assert_array_almost_equal(X, X_orig)
409409

410410
X_orig = X.copy()
411411
with pytest.raises(AssertionError):
412-
pls.predict(X, copy=False),
412+
(pls.predict(X, copy=False),)
413413
assert_array_almost_equal(X, X_orig)
414414

415415
# Make sure copy=True gives same transform and predictions as predict=False

sklearn/datasets/tests/test_openml.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ def _file_name(url, suffix):
105105
)
106106

107107
def _mock_urlopen_shared(url, has_gzip_header, expected_prefix, suffix):
108-
assert url.startswith(
109-
expected_prefix
110-
), f"{expected_prefix!r} does not match {url!r}"
108+
assert url.startswith(expected_prefix), (
109+
f"{expected_prefix!r} does not match {url!r}"
110+
)
111111

112112
data_file_name = _file_name(url, suffix)
113113
data_file_path = resources.files(data_module) / data_file_name
@@ -156,9 +156,9 @@ def _mock_urlopen_download_data(url, has_gzip_header):
156156
)
157157

158158
def _mock_urlopen_data_list(url, has_gzip_header):
159-
assert url.startswith(
160-
url_prefix_data_list
161-
), f"{url_prefix_data_list!r} does not match {url!r}"
159+
assert url.startswith(url_prefix_data_list), (
160+
f"{url_prefix_data_list!r} does not match {url!r}"
161+
)
162162

163163
data_file_name = _file_name(url, ".json")
164164
data_file_path = resources.files(data_module) / data_file_name

sklearn/datasets/tests/test_samples_generator.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,17 @@ def test_make_classification_informative_features():
138138
signs = signs.view(dtype="|S{0}".format(signs.strides[0])).ravel()
139139
unique_signs, cluster_index = np.unique(signs, return_inverse=True)
140140

141-
assert (
142-
len(unique_signs) == n_clusters
143-
), "Wrong number of clusters, or not in distinct quadrants"
141+
assert len(unique_signs) == n_clusters, (
142+
"Wrong number of clusters, or not in distinct quadrants"
143+
)
144144

145145
clusters_by_class = defaultdict(set)
146146
for cluster, cls in zip(cluster_index, y):
147147
clusters_by_class[cls].add(cluster)
148148
for clusters in clusters_by_class.values():
149-
assert (
150-
len(clusters) == n_clusters_per_class
151-
), "Wrong number of clusters per class"
149+
assert len(clusters) == n_clusters_per_class, (
150+
"Wrong number of clusters per class"
151+
)
152152
assert len(clusters_by_class) == n_classes, "Wrong number of classes"
153153

154154
assert_array_almost_equal(
@@ -412,9 +412,9 @@ def test_make_blobs_n_samples_list():
412412
X, y = make_blobs(n_samples=n_samples, n_features=2, random_state=0)
413413

414414
assert X.shape == (sum(n_samples), 2), "X shape mismatch"
415-
assert all(
416-
np.bincount(y, minlength=len(n_samples)) == n_samples
417-
), "Incorrect number of samples per blob"
415+
assert all(np.bincount(y, minlength=len(n_samples)) == n_samples), (
416+
"Incorrect number of samples per blob"
417+
)
418418

419419

420420
def test_make_blobs_n_samples_list_with_centers():
@@ -426,9 +426,9 @@ def test_make_blobs_n_samples_list_with_centers():
426426
)
427427

428428
assert X.shape == (sum(n_samples), 2), "X shape mismatch"
429-
assert all(
430-
np.bincount(y, minlength=len(n_samples)) == n_samples
431-
), "Incorrect number of samples per blob"
429+
assert all(np.bincount(y, minlength=len(n_samples)) == n_samples), (
430+
"Incorrect number of samples per blob"
431+
)
432432
for i, (ctr, std) in enumerate(zip(centers, cluster_stds)):
433433
assert_almost_equal((X[y == i] - ctr).std(), std, 1, "Unexpected std")
434434

@@ -441,9 +441,9 @@ def test_make_blobs_n_samples_centers_none(n_samples):
441441
X, y = make_blobs(n_samples=n_samples, centers=centers, random_state=0)
442442

443443
assert X.shape == (sum(n_samples), 2), "X shape mismatch"
444-
assert all(
445-
np.bincount(y, minlength=len(n_samples)) == n_samples
446-
), "Incorrect number of samples per blob"
444+
assert all(np.bincount(y, minlength=len(n_samples)) == n_samples), (
445+
"Incorrect number of samples per blob"
446+
)
447447

448448

449449
def test_make_blobs_return_centers():
@@ -681,9 +681,9 @@ def test_make_moons():
681681

682682
def test_make_moons_unbalanced():
683683
X, y = make_moons(n_samples=(7, 5))
684-
assert (
685-
np.sum(y == 0) == 7 and np.sum(y == 1) == 5
686-
), "Number of samples in a moon is wrong"
684+
assert np.sum(y == 0) == 7 and np.sum(y == 1) == 5, (
685+
"Number of samples in a moon is wrong"
686+
)
687687
assert X.shape == (12, 2), "X shape mismatch"
688688
assert y.shape == (12,), "y shape mismatch"
689689

sklearn/ensemble/_bagging.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Authors: The scikit-learn developers
44
# SPDX-License-Identifier: BSD-3-Clause
55

6-
76
import itertools
87
import numbers
98
from abc import ABCMeta, abstractmethod

sklearn/ensemble/_forest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class calls the ``fit`` method of each sub-estimator on random samples
3535
# Authors: The scikit-learn developers
3636
# SPDX-License-Identifier: BSD-3-Clause
3737

38-
3938
import threading
4039
from abc import ABCMeta, abstractmethod
4140
from numbers import Integral, Real

sklearn/ensemble/tests/test_forest.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,12 @@ def test_regression_criterion(name, criterion):
168168
reg = ForestRegressor(n_estimators=5, criterion=criterion, random_state=1)
169169
reg.fit(X_reg, y_reg)
170170
score = reg.score(X_reg, y_reg)
171-
assert (
172-
score > 0.93
173-
), "Failed with max_features=None, criterion %s and score = %f" % (
174-
criterion,
175-
score,
171+
assert score > 0.93, (
172+
"Failed with max_features=None, criterion %s and score = %f"
173+
% (
174+
criterion,
175+
score,
176+
)
176177
)
177178

178179
reg = ForestRegressor(
@@ -1068,10 +1069,10 @@ def test_min_weight_fraction_leaf(name):
10681069
node_weights = np.bincount(out, weights=weights)
10691070
# drop inner nodes
10701071
leaf_weights = node_weights[node_weights != 0]
1071-
assert (
1072-
np.min(leaf_weights) >= total_weight * est.min_weight_fraction_leaf
1073-
), "Failed with {0} min_weight_fraction_leaf={1}".format(
1074-
name, est.min_weight_fraction_leaf
1072+
assert np.min(leaf_weights) >= total_weight * est.min_weight_fraction_leaf, (
1073+
"Failed with {0} min_weight_fraction_leaf={1}".format(
1074+
name, est.min_weight_fraction_leaf
1075+
)
10751076
)
10761077

10771078

sklearn/experimental/enable_hist_gradient_boosting.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# Don't remove this file, we don't want to break users code just because the
1414
# feature isn't experimental anymore.
1515

16-
1716
import warnings
1817

1918
warnings.warn(

sklearn/feature_selection/_univariate_selection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Authors: The scikit-learn developers
44
# SPDX-License-Identifier: BSD-3-Clause
55

6-
76
import warnings
87
from numbers import Integral, Real
98

sklearn/gaussian_process/tests/test_gpc.py

Lines changed: 3 additions & 2 deletions
< 10000 /div>
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ def test_custom_optimizer(kernel, global_random_seed):
147147
# Define a dummy optimizer that simply tests 10 random hyperparameters
148148
def optimizer(obj_func, initial_theta, bounds):
149149
rng = np.random.RandomState(global_random_seed)
150-
theta_opt, func_min = initial_theta, obj_func(
151-
initial_theta, eval_gradient=False
150+
theta_opt, func_min = (
151+
initial_theta,
152+
obj_func(initial_theta, eval_gradient=False),
152153
)
153154
for _ in range(10):
154155
theta = np.atleast_1d(

sklearn/gaussian_process/tests/test_gpr.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,9 @@ def test_custom_optimizer(kernel):
394394
# Define a dummy optimizer that simply tests 50 random hyperparameters
395395
def optimizer(obj_func, initial_theta, bounds):
396396
rng = np.random.RandomState(0)
397-
theta_opt, func_min = initial_theta, obj_func(
398-
initial_theta, eval_gradient=False
397+
theta_opt, func_min = (
398+
initial_theta,
399+
obj_func(initial_theta, eval_gradient=False),
399400
)
400401
for _ in range(50):
401402
theta = np.atleast_1d(

sklearn/inspection/_plot/tests/test_plot_partial_dependence.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ def test_plot_partial_dependence_lines_kw(
11871187

11881188
line = disp.lines_[0, 0, -1]
11891189
assert line.get_color() == expected_colors[0], (
1190-
f"{line.get_color()}!={expected_colors[0]}\n" f"{line_kw} and {pd_line_kw}"
1190+
f"{line.get_color()}!={expected_colors[0]}\n{line_kw} and {pd_line_kw}"
11911191
)
11921192
if pd_line_kw is not None:
11931193
if "linestyle" in pd_line_kw:
@@ -1198,9 +1198,9 @@ def test_plot_partial_dependence_lines_kw(
11981198
assert line.get_linestyle() == "--"
11991199

12001200
line = disp.lines_[0, 0, 0]
1201-
assert (
1202-
line.get_color() == expected_colors[1]
1203-
), f"{line.get_color()}!={expected_colors[1]}"
1201+
assert line.get_color() == expected_colors[1], (
1202+
f"{line.get_color()}!={expected_colors[1]}"
1203+
)
12041204
if ice_lines_kw is not None:
12051205
if "linestyle" in ice_lines_kw:
12061206
assert line.get_linestyle() == ice_lines_kw["linestyle"]

sklearn/linear_model/_glm/_newton_solver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def line_search(self, X, y, sample_weight):
254254
check = loss_improvement <= t * armijo_term
255255
if is_verbose:
256256
print(
257-
f" line search iteration={i+1}, step size={t}\n"
257+
f" line search iteration={i + 1}, step size={t}\n"
258258
f" check loss improvement <= armijo term: {loss_improvement} "
259259
f"<= {t * armijo_term} {check}"
260260
)
@@ -300,7 +300,7 @@ def line_search(self, X, y, sample_weight):
300300
self.raw_prediction = raw
301301
if is_verbose:
302302
print(
303-
f" line search successful after {i+1} iterations with "
303+
f" line search successful after {i + 1} iterations with "
304304
f"loss={self.loss_value}."
305305
)
306306

0 commit comments

Comments
 (0)
0