<commit_before>"""
================================
Comparsing various Stochastic Gradient Solvers
================================

An example showing how the different SGDClassifiers perform
on the hand-written digits dataset

"""
# Author: <NAME> <<EMAIL>>
# License: Simplified BSD

import numpy as np
import pylab as pl
from sklearn import datasets
from sklearn.cross_validation import train_test_split
from sklearn.linear_model import SGDClassifier, Perceptron

heldout = [0.95, 0.90, 0.75, 0.50, 0.01]

digits = datasets.load_digits()

classifiers = [
    ("SGD", SGDClassifier()),
    ("Perceptron", Perceptron()),
    ("PA-I",  SGDClassifier(learning_rate='pa1', 
                            eta0=0.001, alpha=0.01)),
    ("PA-II", SGDClassifier(learning_rate='pa2', 
                            eta0=0.001, alpha=0.01)),
    ]

xx = 1-np.array(heldout)
for name,clf in classifiers:
    yy = []
    for i in heldout:
        X_train, X_test, y_train, y_test = train_test_split(digits.data, 
                                                            digits.target, 
                                                            test_size=i)
        clf.fit(X_train,y_train)
        y_pred = clf.predict(X_test)
        yy.append(1-np.mean(y_pred==y_test))
    pl.plot(xx, yy, label=name)

pl.legend(loc="upper right")
pl.xlabel("Proportion train")
pl.ylabel("Test Error Rate")
pl.show()<commit_msg>Added smoothing to example<commit_after>"""
================================
Comparsing various Stochastic Gradient Solvers
================================

An example showing how the different SGDClassifiers perform
on the hand-written digits dataset

"""
# Author: <NAME> <<EMAIL>>
# License: Simplified BSD

import numpy as np
import pylab as pl
from sklearn import datasets
from sklearn.cross_validation import train_test_split
from sklearn.linear_model import SGDClassifier, Perceptron

heldout = [0.95, 0.90, 0.75, 0.50, 0.01]
rounds = 20
digits = datasets.load_digits()

classifiers = [
    ("SGD", SGDClassifier()),
    ("Perceptron", Perceptron()),
    ("PA-I",  SGDClassifier(learning_rate='pa1', 
                            eta0=0.001, alpha=0.01)),
    ("PA-II", SGDClassifier(learning_rate='pa2', 
                            eta0=0.001, alpha=0.01)),
    ]

xx = 1-np.array(heldout)
for name,clf in classifiers:
    yy = []
    for i in heldout:
        yy_ = []
        for r in range(rounds):
            X_train, X_test, y_train, y_test = train_test_split(digits.data, 
                                                                digits.target, 
                                                                test_size=i)
            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_))
    pl.plot(xx, yy, label=name)

pl.legend(loc="upper right")
pl.xlabel("Proportion train")
pl.ylabel("Test Error Rate")
pl.show()
{'fraction_non_alphanumeric': 0.15533650577838207, 'fraction_numerical': 0.024473147518694765, 'mean_word_length': 2.4380841121495327, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6335414', 'n_tokens_mistral': 973, 'n_tokens_neox': 900, 'n_words': 210}