-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Unused Variable Assignment in for k-means #12186
Copy link
Copy link
Closed
Description
Description
in sklearn/cluster/k_means_.py, line 1559:
scikit-learn/sklearn/cluster/k_means_.py
Lines 1559 to 1563 in 2e2e69d
| batch_inertia, centers_squared_diff = _mini_batch_step( | |
| X_valid, sample_weight_valid, | |
| x_squared_norms[validation_indices], cluster_centers, | |
| weight_sums, old_center_buffer, False, distances=None, | |
| verbose=self.verbose) |
Are variables batch_inertia and centers_squared_diff actually used before being reassigned in line 1589?
scikit-learn/sklearn/cluster/k_means_.py
Lines 1583 to 1603 in 2e2e69d
| for iteration_idx in range(n_iter): | |
| # Sample a minibatch from the full dataset | |
| minibatch_indices = random_state.randint( | |
| 0, n_samples, self.batch_size) | |
| # Perform the actual update step on the minibatch data | |
| batch_inertia, centers_squared_diff = _mini_batch_step( | |
| X[minibatch_indices], sample_weight[minibatch_indices], | |
| x_squared_norms[minibatch_indices], | |
| self.cluster_centers_, self.counts_, | |
| old_center_buffer, tol > 0.0, distances=distances, | |
| # Here we randomly choose whether to perform | |
| # random reassignment: the choice is done as a function | |
| # of the iteration index, and the minimum number of | |
| # counts, in order to force this reassignment to happen | |
| # every once in a while | |
| random_reassign=((iteration_idx + 1) | |
| % (10 + int(self.counts_.min())) == 0), | |
| random_state=random_state, | |
| reassignment_ratio=self.reassignment_ratio, | |
| verbose=self.verbose) |
I presume that if n_iter is 0, then the for loop at line 1583 will not be run, which makes the assignment useful. But for k-means is n_iter ever set to 0?
Note
I found this through lgtm.com, as recommended by #12167
Versions
0.20
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels