Submit
Path:
~
/
/
opt
/
alt
/
python35
/
share
/
doc
/
alt-python35-scikit-learn-0.18.1
/
examples
/
linear_model
/
File Content:
plot_sgd_comparison.py
""" ================================== Comparing various online solvers ================================== An example showing how different online solvers perform on the hand-written digits dataset. """ # Author: Rob Zinkov <rob at zinkov dot com> # License: BSD 3 clause import numpy as np import matplotlib.pyplot as plt from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.linear_model import SGDClassifier, Perceptron from sklearn.linear_model import PassiveAggressiveClassifier from sklearn.linear_model import LogisticRegression heldout = [0.95, 0.90, 0.75, 0.50, 0.01] rounds = 20 digits = datasets.load_digits() X, y = digits.data, digits.target classifiers = [ ("SGD", SGDClassifier()), ("ASGD", SGDClassifier(average=True)), ("Perceptron", Perceptron()), ("Passive-Aggressive I", PassiveAggressiveClassifier(loss='hinge', C=1.0)), ("Passive-Aggressive II", PassiveAggressiveClassifier(loss='squared_hinge', C=1.0)), ("SAG", LogisticRegression(solver='sag', tol=1e-1, C=1.e4 / X.shape[0])) ] xx = 1. - np.array(heldout) for name, clf in classifiers: print("training %s" % name) rng = np.random.RandomState(42) yy = [] for i in heldout: yy_ = [] for r in range(rounds): X_train, X_test, y_train, y_test = \ train_test_split(X, y, test_size=i, random_state=rng) clf.fit(X_train, y_train) y_pred = clf.predict(X_test) yy_.append(1 - np.mean(y_pred == y_test)) yy.append(np.mean(yy_)) plt.plot(xx, yy, label=name) plt.legend(loc="upper right") plt.xlabel("Proportion train") plt.ylabel("Test Error Rate") plt.show()
Submit
FILE
FOLDER
Name
Size
Permission
Action
README.txt
135 bytes
0644
lasso_dense_vs_sparse_data.py
1862 bytes
0644
plot_ard.py
2828 bytes
0644
plot_bayesian_ridge.py
2733 bytes
0644
plot_huber_vs_ridge.py
2206 bytes
0644
plot_iris_logistic.py
1679 bytes
0644
plot_lasso_and_elasticnet.py
2074 bytes
0644
plot_lasso_coordinate_descent_path.py
2945 bytes
0644
plot_lasso_lars.py
1080 bytes
0644
plot_lasso_model_selection.py
5431 bytes
0644
plot_logistic.py
1568 bytes
0644
plot_logistic_l1_l2_sparsity.py
2601 bytes
0644
plot_logistic_multinomial.py
2480 bytes
0644
plot_logistic_path.py
1195 bytes
0644
plot_multi_task_lasso_support.py
2319 bytes
0644
plot_ols.py
1936 bytes
0644
plot_ols_3d.py
2040 bytes
0644
plot_ols_ridge_variance.py
2060 bytes
0644
plot_omp.py
2263 bytes
0644
plot_polynomial_interpolation.py
2088 bytes
0644
plot_ransac.py
1859 bytes
0644
plot_ridge_coeffs.py
2785 bytes
0644
plot_ridge_path.py
2138 bytes
0644
plot_robust_fit.py
3050 bytes
0644
plot_sgd_comparison.py
1819 bytes
0644
plot_sgd_iris.py
2202 bytes
0644
plot_sgd_loss_functions.py
1232 bytes
0644
plot_sgd_penalties.py
1877 bytes
0644
plot_sgd_separating_hyperplane.py
1221 bytes
0644
plot_sgd_weighted_samples.py
1458 bytes
0644
plot_sparse_recovery.py
7486 bytes
0644
plot_theilsen.py
3846 bytes
0644
N4ST4R_ID | Naxtarrr