8000 MNT Completes position arg deprecation (#17272) · sstalley/scikit-learn@fd23727 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd23727

Browse files
thomasjpfanadrinjalali
authored andcommitted
MNT Completes position arg deprecation (scikit-learn#17272)
* ENH Adds public functions with position args warning * BUG Circlar import * STY * BUG Add keywords * BUG Fixes warnings * ENH Adds other public functions * CLN Suggestion * CLN Suggestion * REV Revert pairwise * ENH Positoinal args for compute_class_weight
1 parent 467d95f commit fd23727

Some content is hidden

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

44 files changed

+198
-138
lines changed

examples/linear_model/plot_lasso_coordinate_descent_path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
eps = 5e-3 # the smaller it is the longer is the path
3232

3333
print("Computing regularization path using the lasso...")
34-
alphas_lasso, coefs_lasso, _ = lasso_path(X, y, eps, fit_intercept=False)
34+
alphas_lasso, coefs_lasso, _ = lasso_path(X, y, eps=eps, fit_intercept=False)
3535

3636
print("Computing regularization path using the positive lasso...")
3737
alphas_positive_lasso, coefs_positive_lasso, _ = lasso_path(
38-
X, y, eps, positive=True, fit_intercept=False)
38+
X, y, eps=eps, positive=True, fit_intercept=False)
3939
print("Computing regularization path using the elastic net...")
4040
alphas_enet, coefs_enet, _ = enet_path(
4141
X, y, eps=eps, l1_ratio=0.8, fit_intercept=False)

sklearn/calibration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ def predict(self, T):
506506
return expit(-(self.a_ * T + self.b_))
507507

508508

509-
def calibration_curve(y_true, y_prob, normalize=False, n_bins=5,
509+
@_deprecate_positional_args
510+
def calibration_curve(y_true, y_prob, *, normalize=False, n_bins=5,
510511
strategy='uniform'):
511512
"""Compute true and predicted probabilities for a calibration curve.
512513

sklearn/cluster/_affinity_propagation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ def all_equal_similarities():
3030
return all_equal_preferences() and all_equal_similarities()
3131

3232

33-
def affinity_pro 10000 pagation(S, preference=None, convergence_iter=15, max_iter=200,
34-
damping=0.5, copy=True, verbose=False,
33+
@_deprecate_positional_args
34+
def affinity_propagation(S, *, preference=None, convergence_iter=15,
35+
max_iter=200, damping=0.5, copy=True, verbose=False,
3536
return_n_iter=False, random_state='warn'):
3637
"""Perform Affinity Propagation Clustering of data
3738
@@ -411,7 +412,8 @@ def fit(self, X, y=None):
411412

412413
self.cluster_centers_indices_, self.labels_, self.n_iter_ = \
413414
affinity_propagation(
414-
self.affinity_matrix_, self.preference, max_iter=self.max_iter,
415+
self.affinity_matrix_, preference=self.preference,
416+
max_iter=self.max_iter,
415417
convergence_iter=self.convergence_iter, damping=self.damping,
416418
copy=self.copy, verbose=self.verbose, return_n_iter=True,
417419
random_state=self.random_state)

sklearn/cluster/_agglomerative.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ def _single_linkage_tree(connectivity, n_samples, n_nodes, n_clusters,
134134
###############################################################################
135135
# Hierarchical tree building functions
136136

137-
def ward_tree(X, connectivity=None, n_clusters=None, return_distance=False):
137+
@_deprecate_positional_args
138+
def ward_tree(X, *, connectivity=None, n_clusters=None, return_distance=False):
138139
"""Ward clustering based on a Feature matrix.
139140
140141
Recursively merges the pair of clusters that minimally increases
@@ -875,7 +876,7 @@ def fit(self, X, y=None):
875876
distance_threshold = self.distance_threshold
876877

877878
return_distance = distance_threshold is not None
878-
out = memory.cache(tree_builder)(X, connectivity,
879+
out = memory.cache(tree_builder)(X, connectivity=connectivity,
879880
n_clusters=n_clusters,
880881
return_distance=return_distance,
881882
**kwargs)

sklearn/cluster/_dbscan.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
from ._dbscan_inner import dbscan_inner
2121

2222

23-
def dbscan(X, eps=0.5, min_samples=5, metric='minkowski', metric_params=None,
24-
algorithm='auto', leaf_size=30, p=2, sample_weight=None,
25-
n_jobs=None):
23+
@_deprecate_positional_args
24+
def dbscan(X, eps=0.5, *, min_samples=5, metric='minkowski',
25+
metric_params=None, algorithm='auto', leaf_size=30, p=2,
26+
sample_weight=None, n_jobs=None):
2627
"""Perform DBSCAN clustering from vector array or distance matrix.
2728
2829
Read more in the :ref:`User Guide <dbscan>`.

sklearn/cluster/_kmeans.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ def _check_normalize_sample_weight(sample_weight, X):
182182
return sample_weight
183183

184184

185-
def k_means(X, n_clusters, sample_weight=None, init='k-means++',
185+
@_deprecate_positional_args
186+
def k_means(X, n_clusters, *, sample_weight=None, init='k-means++',
186187
precompute_distances='deprecated', n_init=10, max_iter=300,
187188
verbose=False, tol=1e-4, random_state=None, copy_x=True,
188189
n_jobs='deprecated', algorithm="auto", return_n_iter=False):

sklearn/cluster/_mean_shift.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
from ..metrics.pairwise import pairwise_distances_argmin
2727

2828

29-
def estimate_bandwidth(X, quantile=0.3, n_samples=None, random_state=0,
29+
@_deprecate_positional_args
30+
def estimate_bandwidth(X, *, quantile=0.3, n_samples=None, random_state=0,
3031
n_jobs=None):
3132
"""Estimate the bandwidth to use with the mean-shift algorithm.
3233
@@ -106,7 +107,8 @@ def _mean_shift_single_seed(my_mean, X, nbrs, max_iter):
106107
return tuple(my_mean), len(points_within), completed_iterations
107108

108109

109-
def mean_shift(X, bandwidth=None, seeds=None, bin_seeding=False,
110+
@_deprecate_positional_args
111+
def mean_shift(X, *, bandwidth=None, seeds=None, bin_seeding=False,
110112
min_bin_freq=1, cluster_all=True, max_iter=300,
111113
n_jobs=None):
112114
"""Perform mean shift clustering of data using a flat kernel.

sklearn/cluster/_optics.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,13 @@ def fit(self, X, y=None):
261261
# Extract clusters from the calculated orders and reachability
262262
if self.cluster_method == 'xi':
263263
labels_, clusters_ = cluster_optics_xi(
264-
self.reachability_,
265-
self.predecessor_,
266-
self.ordering_,
267-
self.min_samples,
268-
self.min_cluster_size,
269-
self.xi,
270-
self.predecessor_correction)
264+
reachability=self.reachability_,
265+
predecessor=self.predecessor_,
266+
ordering=self.ordering_,
267+
min_samples=self.min_samples,
268+
min_cluster_size=self.min_cluster_size,
269+
xi=self.xi,
270+
predecessor_correction=self.predecessor_correction)
271271
self.cluster_hierarchy_ = clusters_
272272
elif self.cluster_method == 'dbscan':
273273
if self.eps is None:
@@ -279,10 +279,10 @@ def fit(self, X, y=None):
279279
raise ValueError('Specify an epsilon smaller than %s. Got %s.'
280280
% (self.max_eps, eps))
281281

282-
labels_ = cluster_optics_dbscan(self.reachability_,
283-
self.core_distances_,
284-
self.ordering_,
285-
eps)
282+
labels_ = cluster_optics_dbscan(
283+
reachability=self.reachability_,
284+
core_distances=self.core_distances_,
285+
ordering=self.ordering_, eps=eps)
286286

287287
self.labels_ = labels_
288288
return self
@@ -339,7 +339,8 @@ def _compute_core_distances_(X, neighbors, min_samples, working_memory):
339339
return core_distances
340340

341341

342-
def compute_optics_graph(X, min_samples, max_eps, metric, p, metric_params,
342+
@_deprecate_positional_args
343+
def compute_optics_graph(X, *, min_samples, max_eps, metric, p, metric_params,
343344
algorithm, leaf_size, n_jobs):
344345
"""Computes the OPTICS reachability graph.
345346
@@ -538,7 +539,8 @@ def _set_reach_dist(core_distances_, reachability_, predecessor_,
538539
predecessor_[unproc[improved]] = point_index
539540

540541

541-
def cluster_optics_dbscan(reachability, core_distances, ordering, eps):
542+
@_deprecate_positional_args
543+
def cluster_optics_dbscan(*, reachability, core_distances, ordering, eps):
542544
"""Performs DBSCAN extraction for an arbitrary epsilon.
543545
544546
Extracting the clusters runs in linear time. Note that this results in
@@ -577,7 +579,7 @@ def cluster_optics_dbscan(reachability, core_distances, ordering, eps):
577579
return labels
578580

579581

580-
def cluster_optics_xi(reachability, predecessor, ordering, min_samples,
582+
def cluster_optics_xi(*, reachability, predecessor, ordering, min_samples,
581583
min_cluster_size=None, xi=0.05,
582584
predecessor_correction=True):
583585
"""Automatically extract clusters according to the Xi-steep method.

sklearn/cluster/_spectral.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
from ._kmeans import k_means
1919

2020

21-
def discretize(vectors, copy=True, max_svd_restarts=30, n_iter_max=20,
21+
@_deprecate_positional_args
22+
def discretize(vectors, *, copy=True, max_svd_restarts=30, n_iter_max=20,
2223
random_state=None):
2324
"""Search for a partition matrix (clustering) which is closest to the
2425
eigenvector embedding.
@@ -156,7 +157,8 @@ def discretize(vectors, copy=True, max_svd_restarts=30, n_iter_max=20,
156157
return labels
157158

158159

159-
def spectral_clustering(affinity, n_clusters=8, n_components=None,
160+
@_deprecate_positional_args
161+
def spectral_clustering(affinity, *, n_clusters=8, n_components=None,
160162
eigen_solver=None, random_state=None, n_init=10,
161163
eigen_tol=0.0, assign_labels='kmeans'):
162164
"""Apply clustering to a projection of the normalized Laplacian.

sklearn/cluster/tests/test_hierarchical.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ def test_structured_linkage_tree():
7474
connectivity = grid_to_graph(*mask.shape)
7575
for tree_builder in _TREE_BUILDERS.values():
7676
children, n_components, n_leaves, parent = \
77-
tree_builder(X.T, connectivity)
77+
tree_builder(X.T, connectivity=connectivity)
7878
n_nodes = 2 * X.shape[1] - 1
7979
assert len(children) + n_leaves == n_nodes
8080
# Check that ward_tree raises a ValueError with a connectivity matrix
8181
# of the wrong shape
8282
with pytest.raises(ValueError):
83-
tree_builder(X.T, np.ones((4, 4)))
83+
tree_builder(X.T, connectivity=np.ones((4, 4)))
8484
# Check that fitting with no samples raises an error
8585
with pytest.raises(ValueError):
86-
tree_builder(X.T[:0], connectivity)
86+
tree_builder(X.T[:0], connectivity=connectivity)
8787

8888

8989
def test_unstructured_linkage_tree():
@@ -116,7 +116,8 @@ def test_height_linkage_tree():
116116
X = rng.randn(50, 100)
117117
connectivity = grid_to_graph(*mask.shape)
118118
for linkage_func in _TREE_BUILDERS.values():
119-
children, n_nodes, n_leaves, parent = linkage_func(X.T, connectivity)
119+
children, n_nodes, n_leaves, parent = linkage_func(
120+
X.T, connectivity=connectivity)
120121
n_nodes = 2 * X.shape[1] - 1
121122
assert len(children) + n_leaves == n_nodes
122123

@@ -298,7 +299,8 @@ def test_sparse_scikit_vs_scipy():
298299
out = hierarchy.linkage(X, method=linkage)
299300

300301
children_ = out[:, :2].astype(np.int, copy=False)
301-
children, _, n_leaves, _ = _TREE_BUILDERS[linkage](X, connectivity)
302+
children, _, n_leaves, _ = _TREE_BUILDERS[linkage](
303+
X, connectivity=connectivity)
302304

303305
# Sort the order of child nodes per row for consistency
304306
children.sort(axis=1)

0 commit comments

Comments
 (0)
0