|
27 | 27 | import numpy as np
|
28 | 28 |
|
29 | 29 | from sklearn.datasets import fetch_openml
|
| 30 | +from sklearn.datasets import load_digits |
30 | 31 | from sklearn.linear_model import LogisticRegression
|
31 | 32 | from sklearn.model_selection import train_test_split
|
32 | 33 | from sklearn.preprocessing import StandardScaler
|
33 | 34 | from sklearn.utils import check_random_state
|
34 | 35 |
|
35 | 36 | t0 = time.time()
|
36 | 37 |
|
37 |
| -# Load data from https://www.openml.org/d/554 |
38 |
| -X, y = fetch_openml("mnist_784", version=1, return_X_y=True, as_frame=False) |
| 38 | +# Load toy dataset |
| 39 | +X, y = load_digits(return_X_y=True, as_frame=False) |
| 40 | + |
| 41 | +# Alternatively, load larger MNIST data set from OpenML, https://www.openml.org/d/554 |
| 42 | +# X, y = fetch_openml("mnist_784", version=1, return_X_y=True, as_frame=False) |
39 | 43 |
|
40 | 44 | random_state = check_random_state(0)
|
41 | 45 | permutation = random_state.permutation(X.shape[0])
|
|
52 | 56 | X_train = scaler.fit_transform(X_train)
|
53 | 57 | X_test = scaler.transform(X_test)
|
54 | 58 |
|
55 |
| -clf = LogisticRegression(C=50.0 / train_samples, penalty="l1", solver="saga", tol=0.1, random_state=random_state) |
| 59 | +clf = LogisticRegression(C=20.0 / train_samples, penalty="l1", solver="saga", tol=0.1, random_state=random_state) |
56 | 60 | clf.fit(X_train, y_train)
|
57 | 61 | sparsity = np.mean(clf.coef_ == 0) * 100
|
58 | 62 | score = clf.score(X_test, y_test)
|
|
0 commit comments