ageron / ageron/handson-ml

Chapter 3 - sgd_clf failed to converge with scaled data

Open
#584 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
25.6k
Forks
12.7k
PR merge metrics
PR metrics pending

Description

At the end of the section "Multiclass Classification," there's an example that's supposed to demonstrate improved performance on the stochastic gradient descent classifier when the data is scaled. Whenever I run cross_val_score on this example, it fails to converge. What could be causing this?

```from sklearn.preprocessing import StandardScaler
sgd_clf.random_state_ = 42
sgd_clf.max_iter_ = 8000
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train.astype(np.float64))
score(sgd_clf, X_train_scaled, y_train, cv=3, scoring="accuracy")
cross_val_score(sgd_clf, X_train_scaled, y_train, cv=3, scoring="accuracy")
/Users/mciul/anaconda3/lib/python3.8/site-packages/sklearn/linear_model/_stochastic_gradient.py:570: ConvergenceWarning: Maximum number of iteration reached before convergence. Consider increasing max_iter to improve the fit.
warnings.warn("Maximum number of iteration reached before "
```
I've been experimenting with changing the initial random state and max iterations, as above. Unless I'm misunderstanding how the classifier works, and setting these values doesn't do anything after initialization?

Any help would be appreciated. I know this isn't exactly the right place to post, but I'm not sure where else to go. Let me know if there is a forum that would be more appropriate.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.