-
-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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
[MRG] Added n_iter_ parameters across all iterative solvers #3360
Conversation
@@ -224,6 +224,9 @@ def k_means(X, n_clusters, init='k-means++', precompute_distances=True, | |||
The final value of the inertia criterion (sum of squared distances to | |||
the closest centroid for all observations in the training set). | |||
|
|||
iters: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather call it n_iter
to be consistent with the naming convention.
Please add a check somewhere appropriate in |
@ogrisel I'm working on it, but it would be better to complete the previous PR first. so that I can rebase on top of that, wdyt? |
Yes. Feel free to do as is easiest for you. |
@@ -60,6 +60,9 @@ def affinity_propagation(S, preference=None, convergence_iter=15, max_iter=200, | |||
labels : array, shape (n_samples,) | |||
cluster labels for each point | |||
|
|||
iters: int | |||
number of iterations run. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we cannot change output of public functions like this :(
I agree with Alex that maintaining API compatibility is extremely important. In order to maintain this compatibility and at the same time return this parameters you would need to add a keyword to public functions such as For the private functions my opinion is that it's OK to break compatibility and just return the number of iterations as you are currently doing. |
@@ -351,6 +357,9 @@ def _kmeans_single(X, n_clusters, x_squared_norms, max_iter=300, | |||
inertia: float | |||
The final value of the inertia criterion (sum of squared distances to | |||
the closest centroid for all observations in the training set). | |||
|
|||
iters: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space before : in docstrings.
This needs careful checking because sometimes it has to be |
What's the status on this PR. I have the feeling that it has been superseeded by another, but I am lost with all what's happening. |
I shall complete work on this as soon as the Log Reg CV PR is over. |
Technically that's also the number of iterations in the solver. True it's upper bounded by |
@@ -60,6 +64,9 @@ def affinity_propagation(S, preference=None, convergence_iter=15, max_iter=200, | |||
labels : array, shape (n_samples,) | |||
cluster labels for each point | |||
|
|||
n_iter : int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only conditionally returned, which should be explicitly specified.
@vene @ogrisel @agramfort I believe the PR is no longer a WIP. Please review :) |
@arjoly Could you please verify that the new test in the |
@@ -368,7 +385,7 @@ def _kmeans_single(X, n_clusters, x_squared_norms, max_iter=300, | |||
distances = np.zeros(shape=(X.shape[0],), dtype=np.float64) | |||
|
|||
# iterations | |||
for i in range(max_iter): | |||
for n_iter in range(max_iter): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather leave i
as the iteration index variable and return i + 1 instead. The docstring can keep the n_iter
name for the return value.
@ogrisel thanks for the reviews, do you have any more comments? |
Estimator = estimator(alpha=0.) | ||
else: | ||
Estimator = estimator() | ||
if hasattr(Estimator, "max_iter"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Estimator is an instance and should not start with a capital E. estimator is the class name and shall be the one called Estimator
if name == 'AffinityPropagation': | ||
Estimator.fit(X) | ||
else: | ||
Estimator.fit(X, y_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Estimator -> estimator
besides LGTM as travis is happy |
if name == 'LassoLars': | ||
Estimator = estimator(alpha=0.) | ||
else: | ||
Estimator = estimator() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Estimator()?
if name in (['Ridge', 'SVR', 'NuSVR', 'NuSVC', | ||
'RidgeClassifier', 'SVC', 'RandomizedLasso']): | ||
continue | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arjoly I looked into Ridge but out of the three solvers in Ridge only one returns an iteration parameter, so I left it so that it is consistent.
@arjoly @agramfort @ogrisel done. anymore comments? |
merged by rebase. Thanks @MechCoder ! |
Do you think this needs a whats_new entry, to make users know that this is available? |
Yes. It does not hurt. |
Done in a894b2e |
Added a n_iter parameter across all iterative solvers that have a max_iter parameter.
Models that have the max_iter parameter.
Dependent on external solvers like arpack, so cannot access the iter param
Dependent on LibSVM