helpers.py
def learning_curves(estimator, X, y, ylim=None, cv=10, title='', n_jobs=1,
                        train_sizes=np.linspace(.1, 1.0, 10), leg_loc='best',
                        scoring='accuracy', baseline=0, baseline_loc=1.0,
                        random_seed=None):
    """
    Generate a simple plot of the test and training learning curves.
    Citation: http://scikit-learn.org/stable/auto_examples/model_selection/plot_learning_curve.html

    Parameters
    ----------
    estimator : object type that implements the "fit" and "predict" methods
        An object of that type which is cloned for each validation.

    X : array-like, shape (n_samples, n_features)
        Training vector, where n_samples is the number of samples and
        n_features is the number of features.

    y : array-like, shape (n_samples) or (n_samples, n_features), optional
        Target relative to X for classification or regression;
        None for unsupervised learning.

    ylim : tuple, shape (ymin, ymax), optional
        Defines minimum and maximum yvalues plotted.

    title : string, optional
        Title for the chart (default no title).

    cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:
          - None, to use the default 3-fold cross-validation,
          - integer, to specify the number of folds.
          - An object to be used as a cross-validation generator.
          - An iterable yielding train/test splits.

        For integer/None inputs, if ``y`` is binary or multiclass,
        :class:`StratifiedKFold` used. If the estimator is not a classifier
        or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validators that can be used here.

    n_jobs : integer, optional
        Number of jobs to run in parallel (default 1).

    train_sizes : array-like, shape(user-defined, 1)
        Training size increments as proportion between 0.0 and 1.0.

    scoring : string
        Scoring method for learning curve method (default 'Accuracy').

    baseline : float, optional
        Baseline accuracy for plotting for comparison.

    baseline_loc : float, optional
        Multiple of times to move baseline label to the right from first point.

    leg_loc : string, optional
        Location for legend (default 'best').

    random_seed : int, optional
        Random seed (if any) to initialize before computing learning curves.
    """

    if random_seed is not None:
        np.random.seed(random_seed)

    colors = ['#1b9e77', '#d95f02', '#7570b3', '#e7298a', '#66a61e']
    plt.figure()
    if len(title) > 0:
        plt.title(title)
    if ylim is not None:
        plt.ylim(*ylim)
    plt.xlabel("Training examples")
    plt.ylabel(scoring)
    train_sizes, train_scores, test_scores = learning_curve(
        estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes,
        scoring=scoring)
    train_scores_mean = np.mean(train_scores, axis=1)
    train_scores_std = np.std(train_scores, axis=1)
    test_scores_mean = np.mean(test_scores, axis=1)
    test_scores_std = np.std(test_scores, axis=1)
    plt.grid()

    plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color=colors[-2])
    plt.fill_between(train_sizes, test_scores_mean - test_scores_std,
                     test_scores_mean + test_scores_std, alpha=0.1, color=colors[-1])
    plt.plot(train_sizes, train_scores_mean, 'o-', color=colors[-2],
             label="Training score")
    plt.plot(train_sizes, test_scores_mean, 'o-', color=colors[-1],
             label="Cross-validation score")

    # Plot a baseline accuracy if provided
    if baseline > 0:
        plt.axhline(baseline, color = 'black', linestyle='dashed')
        plt.text(baseline_loc * train_sizes[1], baseline, 'baseline',
                     bbox=dict(facecolor='white'))

    plt.legend(loc=leg_loc)
    plt.show()

    Generate a simple plot of the test and training learning curves.
    Citation: http://scikit-learn.org/stable/auto_examples/model_selection/plot_learning_curve.html

    Parameters
    ----------
    estimator : object type that implements the "fit" and "predict" methods
        An object of that type which is cloned for each validation.

    X : array-like, shape (n_samples, n_features)
        Training vector, where n_samples is the number of samples and
        n_features is the number of features.

    y : array-like, shape (n_samples) or (n_samples, n_features), optional
        Target relative to X for classification or regression;
        None for unsupervised learning.

    ylim : tuple, shape (ymin, ymax), optional
        Defines minimum and maximum yvalues plotted.

    title : string, optional
        Title for the chart (default no title).

    cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:
          - None, to use the default 3-fold cross-validation,
          - integer, to specify the number of folds.
          - An object to be used as a cross-validation generator.
          - An iterable yielding train/test splits.

        For integer/None inputs, if ``y`` is binary or multiclass,
        :class:`StratifiedKFold` used. If the estimator is not a classifier
        or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validators that can be used here.

    n_jobs : integer, optional
        Number of jobs to run in parallel (default 1).

    train_sizes : array-like, shape(user-defined, 1)
        Training size increments as proportion between 0.0 and 1.0.

    scoring : string
        Scoring method for learning curve method (default 'Accuracy').

    baseline : float, optional
        Baseline accuracy for plotting for comparison.

    baseline_loc : float, optional
        Multiple of times to move baseline label to the right from first point.

    leg_loc : string, optional
        Location for legend (default 'best').

    random_seed : int, optional
        Random seed (if any) to initialize before computing learning curves.
    
Generate a simple plot of the test and training learning curves.
Generate a simple plot of the test and training learning curves .
def learning_curves(estimator, X, y, ylim=None, cv=10, title='', n_jobs=1,
                        train_sizes=np.linspace(.1, 1.0, 10), leg_loc='best',
                        scoring='accuracy', baseline=0, baseline_loc=1.0,
                        random_seed=None):
    if random_seed is not None:
        np.random.seed(random_seed)
    colors = ['#1b9e77', '#d95f02', '#7570b3', '#e7298a', '#66a61e']
    plt.figure()
    if len(title) > 0:
        plt.title(title)
    if ylim is not None:
        plt.ylim(*ylim)
    plt.xlabel("Training examples")
    plt.ylabel(scoring)
    train_sizes, train_scores, test_scores = learning_curve(
        estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes,
        scoring=scoring)
    train_scores_mean = np.mean(train_scores, axis=1)
    train_scores_std = np.std(train_scores, axis=1)
    test_scores_mean = np.mean(test_scores, axis=1)
    test_scores_std = np.std(test_scores, axis=1)
    plt.grid()
    plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color=colors[-2])
    plt.fill_between(train_sizes, test_scores_mean - test_scores_std,
                     test_scores_mean + test_scores_std, alpha=0.1, color=colors[-1])
    plt.plot(train_sizes, train_scores_mean, 'o-', color=colors[-2],
             label="Training score")
    plt.plot(train_sizes, test_scores_mean, 'o-', color=colors[-1],
             label="Cross-validation score")
    if baseline > 0:
        plt.axhline(baseline, color = 'black', linestyle='dashed')
        plt.text(baseline_loc * train_sizes[1], baseline, 'baseline',
                     bbox=dict(facecolor='white'))
    plt.legend(loc=leg_loc)
    plt.show()
def learning_curves ( estimator , X , y , ylim = None , cv = 10 , title = '' , n_jobs = 1 , train_sizes = np . linspace ( .1 , 1.0 , 10 ) , leg_loc = 'best' , scoring = 'accuracy' , baseline = 0 , baseline_loc = 1.0 , random_seed = None ) : if random_seed is not None : np . random . seed ( random_seed ) colors = [ '#1b9e77' , '#d95f02' , '#7570b3' , '#e7298a' , '#66a61e' ] plt . figure ( ) if len ( title ) > 0 : plt . title ( title ) if ylim is not None : plt . ylim ( * ylim ) plt . xlabel ( "Training examples" ) plt . ylabel ( scoring ) train_sizes , train_scores , test_scores = learning_curve ( estimator , X , y , cv = cv , n_jobs = n_jobs , train_sizes = train_sizes , scoring = scoring ) train_scores_mean = np . mean ( train_scores , axis = 1 ) train_scores_std = np . std ( train_scores , axis = 1 ) test_scores_mean = np . mean ( test_scores , axis = 1 ) test_scores_std = np . std ( test_scores , axis = 1 ) plt . grid ( ) plt . fill_between ( train_sizes , train_scores_mean - train_scores_std , train_scores_mean + train_scores_std , alpha = 0.1 , color = colors [ - 2 ] ) plt . fill_between ( train_sizes , test_scores_mean - test_scores_std , test_scores_mean + test_scores_std , alpha = 0.1 , color = colors [ - 1 ] ) plt . plot ( train_sizes , train_scores_mean , 'o-' , color = colors [ - 2 ] , label = "Training score" ) plt . plot ( train_sizes , test_scores_mean , 'o-' , color = colors [ - 1 ] , label = "Cross-validation score" ) if baseline > 0 : plt . axhline ( baseline , color = 'black' , linestyle = 'dashed' ) plt . text ( baseline_loc * train_sizes [ 1 ] , baseline , 'baseline' , bbox = dict ( facecolor = 'white' ) ) plt . legend ( loc = leg_loc ) plt . show ( )
Generate a simple plot of the test and training learning curves.
Generate a simple plot of the test and training learning curves .
"""
    Generate a simple plot of the test and training learning curves.
    Citation: http://scikit-learn.org/stable/auto_examples/model_selection/plot_learning_curve.html

    Parameters
    ----------
    estimator : object type that implements the "fit" and "predict" methods
        An object of that type which is cloned for each validation.

    X : array-like, shape (n_samples, n_features)
        Training vector, where n_samples is the number of samples and
        n_features is the number of features.

    y : array-like, shape (n_samples) or (n_samples, n_features), optional
        Target relative to X for classification or regression;
        None for unsupervised learning.

    ylim : tuple, shape (ymin, ymax), optional
        Defines minimum and maximum yvalues plotted.

    title : string, optional
        Title for the chart (default no title).

    cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:
          - None, to use the default 3-fold cross-validation,
          - integer, to specify the number of folds.
          - An object to be used as a cross-validation generator.
          - An iterable yielding train/test splits.

        For integer/None inputs, if ``y`` is binary or multiclass,
        :class:`StratifiedKFold` used. If the estimator is not a classifier
        or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validators that can be used here.

    n_jobs : integer, optional
        Number of jobs to run in parallel (default 1).

    train_sizes : array-like, shape(user-defined, 1)
        Training size increments as proportion between 0.0 and 1.0.

    scoring : string
        Scoring method for learning curve method (default 'Accuracy').

    baseline : float, optional
        Baseline accuracy for plotting for comparison.

    baseline_loc : float, optional
        Multiple of times to move baseline label to the right from first point.

    leg_loc : string, optional
        Location for legend (default 'best').

    random_seed : int, optional
        Random seed (if any) to initialize before computing learning curves.
    """ # Plot a baseline accuracy if provided

estimator
An object of that type which is cloned for each validation.
An object of that type which is cloned for each validation .
X
Training vector, where n_samples is the number of samples and
n_features is the number of features.
Training vector where n_samples is the number of samples and n_features is the number of features .
y
Target relative to X for classification or regression;
None for unsupervised learning.
Target relative to X for classification or regression ; None for unsupervised learning .
ylim
Defines minimum and maximum yvalues plotted.
Defines minimum and maximum yvalues plotted .
cv
Determines the cross-validation splitting strategy.
Possible inputs for cv are:
None, to use the default 3-fold cross-validation,
integer, to specify the number of folds.
An object to be used as a cross-validation generator.
An iterable yielding train/test splits.

For integer/None inputs, if ``y`` is binary or multiclass,
:class:`StratifiedKFold` used. If the estimator is not a classifier
or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.

Refer :ref:`User Guide ` for the various
cross-validators that can be used here.
Determines the cross - validation splitting strategy . Possible inputs for cv are : None to use the default 3 - fold cross - validation integer to specify the number of folds . An object to be used as a cross - validation generator . An iterable yielding train / test splits . For integer / None inputs if ` ` y ` ` is binary or multiclass : class : ` StratifiedKFold ` used . If the estimator is not a classifier or if ` ` y ` ` is neither binary nor multiclass : class : ` KFold ` is used . Refer : ref : ` User Guide ` for the various cross - validators that can be used here .
3-fold
title
Title for the chart (default no title).
Title for the chart ( default no title ) .
n_jobs
Number of jobs to run in parallel (default 1).
Number of jobs to run in parallel ( default 1 ) .
train_sizes
Training size increments as proportion between 0.0 and 1.0.
Training size increments as proportion between 0 . 0 and 1 . 0 .
leg_loc
Location for legend (default 'best').
Location for legend ( default ' best ' ) .
scoring
Scoring method for learning curve method (default 'Accuracy').
Scoring method for learning curve method ( default ' Accuracy ' ) .
baseline
Baseline accuracy for plotting for comparison.
Baseline accuracy for plotting for comparison .
baseline_loc
Multiple of times to move baseline label to the right from first point.
Multiple of times to move baseline label to the right from first point .
random_seed
Random seed (if any) to initialize before computing learning curves.
Random seed ( if any ) to initialize before computing learning curves .