import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

from sklearn.model_selection import learning_curve

# Plot learning curve
def plot_learning_curve(estimator, title, X, y, ylim=None, cv=None,
                        n_jobs=1, train_sizes=np.linspace(.1, 1.0, 5)):
    plt.figure()
    plt.title(title)
    if ylim is not None:
        plt.ylim(*ylim)
    plt.xlabel("Training examples")
    plt.ylabel("Score")
    train_sizes, train_scores, test_scores = learning_curve(
        estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes)
    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(True)

    plt.fill_between(train_sizes, train_scores_mean - train_scores_std,
                     train_scores_mean + train_scores_std, alpha=0.1,
                     color="r")
    plt.fill_between(train_sizes, test_scores_mean - test_scores_std,
                     test_scores_mean + test_scores_std, alpha=0.1, color="g")
    plt.plot(train_sizes, train_scores_mean, 'o-', color="r",
             label="Training score")
    plt.plot(train_sizes, test_scores_mean, 'o-', color="g",
             label="Validation score")

    plt.legend(loc="best")
    plt.show()
    return plt

# Plot validation curve
def plot_validation_curve(estimator, title, X, y, param_name, param_range, ylim=None, cv=None,
                        n_jobs=1, train_sizes=np.linspace(.1, 1.0, 5)):
    train_scores, test_scores = validation_curve(estimator, X, y, param_name, param_range, cv)
    train_mean = np.mean(train_scores, axis=1)
    train_std = np.std(train_scores, axis=1)
    test_mean = np.mean(test_scores, axis=1)
    test_std = np.std(test_scores, axis=1)
    plt.plot(param_range, train_mean, color='r', marker='o', markersize=5, label='Training score')
    plt.fill_between(param_range, train_mean + train_std, train_mean - train_std, alpha=0.15, color='r')
    plt.plot(param_range, test_mean, color='g', linestyle='--', marker='s', markersize=5, label='Validation score')
    plt.fill_between(param_range, test_mean + test_std, test_mean - test_std, alpha=0.15, color='g')
    plt.grid(True) 
    plt.xscale('log')
    plt.legend(loc='best') 
    plt.xlabel('Parameter') 
    plt.ylabel('Score') 
    plt.ylim(ylim)

[(10, 'numpy.linspace', 'np.linspace', True, 'import numpy as np\n'), (11, 'matplotlib.pyplot.figure', 'plt.figure', True, 'import matplotlib.pyplot as plt\n'), (12, 'matplotlib.pyplot.title', 'plt.title', True, 'import matplotlib.pyplot as plt\n'), (15, 'matplotlib.pyplot.xlabel', 'plt.xlabel', True, 'import matplotlib.pyplot as plt\n'), (16, 'matplotlib.pyplot.ylabel', 'plt.ylabel', True, 'import matplotlib.pyplot as plt\n'), (17, 'sklearn.model_selection.learning_curve', 'learning_curve', False, 'from sklearn.model_selection import learning_curve\n'), (19, 'numpy.mean', 'np.mean', True, 'import numpy as np\n'), (20, 'numpy.std', 'np.std', True, 'import numpy as np\n'), (21, 'numpy.mean', 'np.mean', True, 'import numpy as np\n'), (22, 'numpy.std', 'np.std', True, 'import numpy as np\n'), (23, 'matplotlib.pyplot.grid', 'plt.grid', True, 'import matplotlib.pyplot as plt\n'), (25, 'matplotlib.pyplot.fill_between', 'plt.fill_between', True, 'import matplotlib.pyplot as plt\n'), (28, 'matplotlib.pyplot.fill_between', 'plt.fill_between', True, 'import matplotlib.pyplot as plt\n'), (30, 'matplotlib.pyplot.plot', 'plt.plot', True, 'import matplotlib.pyplot as plt\n'), (32, 'matplotlib.pyplot.plot', 'plt.plot', True, 'import matplotlib.pyplot as plt\n'), (35, 'matplotlib.pyplot.legend', 'plt.legend', True, 'import matplotlib.pyplot as plt\n'), (36, 'matplotlib.pyplot.show', 'plt.show', True, 'import matplotlib.pyplot as plt\n'), (41, 'numpy.linspace', 'np.linspace', True, 'import numpy as np\n'), (43, 'numpy.mean', 'np.mean', True, 'import numpy as np\n'), (44, 'numpy.std', 'np.std', True, 'import numpy as np\n'), (45, 'numpy.mean', 'np.mean', True, 'import numpy as np\n'), (46, 'numpy.std', 'np.std', True, 'import numpy as np\n'), (47, 'matplotlib.pyplot.plot', 'plt.plot', True, 'import matplotlib.pyplot as plt\n'), (48, 'matplotlib.pyplot.fill_between', 'plt.fill_between', True, 'import matplotlib.pyplot as plt\n'), (49, 'matplotlib.pyplot.plot', 'plt.plot', True, 'import matplotlib.pyplot as plt\n'), (50, 'matplotlib.pyplot.fill_between', 'plt.fill_between', True, 'import matplotlib.pyplot as plt\n'), (51, 'matplotlib.pyplot.grid', 'plt.grid', True, 'import matplotlib.pyplot as plt\n'), (52, 'matplotlib.pyplot.xscale', 'plt.xscale', True, 'import matplotlib.pyplot as plt\n'), (53, 'matplotlib.pyplot.legend', 'plt.legend', True, 'import matplotlib.pyplot as plt\n'), (54, 'matplotlib.pyplot.xlabel', 'plt.xlabel', True, 'import matplotlib.pyplot as plt\n'), (55, 'matplotlib.pyplot.ylabel', 'plt.ylabel', True, 'import matplotlib.pyplot as plt\n'), (56, 'matplotlib.pyplot.ylim', 'plt.ylim', True, 'import matplotlib.pyplot as plt\n'), (14, 'matplotlib.pyplot.ylim', 'plt.ylim', True, 'import matplotlib.pyplot as plt\n')]