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)

[((282, 306), 'numpy.linspace', 'np.linspace', (['(0.1)', '(1.0)', '(5)'], {}), '(0.1, 1.0, 5)\n', (293, 306), True, 'import numpy as np\n'), ((312, 324), 'matplotlib.pyplot.figure', 'plt.figure', ([], {}), '()\n', (322, 324), True, 'import matplotlib.pyplot as plt\n'), ((329, 345), 'matplotlib.pyplot.title', 'plt.title', (['title'], {}), '(title)\n', (338, 345), True, 'import matplotlib.pyplot as plt\n'), ((399, 430), 'matplotlib.pyplot.xlabel', 'plt.xlabel', (['"""Training examples"""'], {}), "('Training examples')\n", (409, 430), True, 'import matplotlib.pyplot as plt\n'), ((435, 454), 'matplotlib.pyplot.ylabel', 'plt.ylabel', (['"""Score"""'], {}), "('Score')\n", (445, 454), True, 'import matplotlib.pyplot as plt\n'), ((500, 578), 'sklearn.model_selection.learning_curve', 'learning_curve', (['estimator', 'X', 'y'], {'cv': 'cv', 'n_jobs': 'n_jobs', 'train_sizes': 'train_sizes'}), '(estimator, X, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes)\n', (514, 578), False, 'from sklearn.model_selection import learning_curve\n'), ((612, 641), 'numpy.mean', 'np.mean', (['train_scores'], {'axis': '(1)'}), '(train_scores, axis=1)\n', (619, 641), True, 'import numpy as np\n'), ((665, 693), 'numpy.std', 'np.std', (['train_scores'], {'axis': '(1)'}), '(train_scores, axis=1)\n', (671, 693), True, 'import numpy as np\n'), ((717, 745), 'numpy.mean', 'np.mean', (['test_scores'], {'axis': '(1)'}), '(test_scores, axis=1)\n', (724, 745), True, 'import numpy as np\n'), ((768, 795), 'numpy.std', 'np.std', (['test_scores'], {'axis': '(1)'}), '(test_scores, axis=1)\n', (774, 795), True, 'import numpy as np\n'), ((800, 814), 'matplotlib.pyplot.grid', 'plt.grid', (['(True)'], {}), '(True)\n', (808, 814), True, 'import matplotlib.pyplot as plt\n'), ((820, 952), 'matplotlib.pyplot.fill_between', 'plt.fill_between', (['train_sizes', '(train_scores_mean - train_scores_std)', '(train_scores_mean + train_scores_std)'], {'alpha': '(0.1)', 'color': '"""r"""'}), "(train_sizes, train_scores_mean - train_scores_std, \n    train_scores_mean + train_scores_std, alpha=0.1, color='r')\n", (836, 952), True, 'import matplotlib.pyplot as plt\n'), ((994, 1122), 'matplotlib.pyplot.fill_between', 'plt.fill_between', (['train_sizes', '(test_scores_mean - test_scores_std)', '(test_scores_mean + test_scores_std)'], {'alpha': '(0.1)', 'color': '"""g"""'}), "(train_sizes, test_scores_mean - test_scores_std, \n    test_scores_mean + test_scores_std, alpha=0.1, color='g')\n", (1010, 1122), True, 'import matplotlib.pyplot as plt\n'), ((1143, 1229), 'matplotlib.pyplot.plot', 'plt.plot', (['train_sizes', 'train_scores_mean', '"""o-"""'], {'color': '"""r"""', 'label': '"""Training score"""'}), "(train_sizes, train_scores_mean, 'o-', color='r', label=\n    'Training score')\n", (1151, 1229), True, 'import matplotlib.pyplot as plt\n'), ((1242, 1329), 'matplotlib.pyplot.plot', 'plt.plot', (['train_sizes', 'test_scores_mean', '"""o-"""'], {'color': '"""g"""', 'label': '"""Validation score"""'}), "(train_sizes, test_scores_mean, 'o-', color='g', label=\n    'Validation score')\n", (1250, 1329), True, 'import matplotlib.pyplot as plt\n'), ((1343, 1365), 'matplotlib.pyplot.legend', 'plt.legend', ([], {'loc': '"""best"""'}), "(loc='best')\n", (1353, 1365), True, 'import matplotlib.pyplot as plt\n'), ((1370, 1380), 'matplotlib.pyplot.show', 'plt.show', ([], {}), '()\n', (1378, 1380), True, 'import matplotlib.pyplot as plt\n'), ((1562, 1586), 'numpy.linspace', 'np.linspace', (['(0.1)', '(1.0)', '(5)'], {}), '(0.1, 1.0, 5)\n', (1573, 1586), True, 'import numpy as np\n'), ((1700, 1729), 'numpy.mean', 'np.mean', (['train_scores'], {'axis': '(1)'}), '(train_scores, axis=1)\n', (1707, 1729), True, 'import numpy as np\n'), ((1746, 1774), 'numpy.std', 'np.std', (['train_scores'], {'axis': '(1)'}), '(train_scores, axis=1)\n', (1752, 1774), True, 'import numpy as np\n'), ((1791, 1819), 'numpy.mean', 'np.mean', (['test_scores'], {'axis': '(1)'}), '(test_scores, axis=1)\n', (1798, 1819), True, 'import numpy as np\n'), ((1835, 1862), 'numpy.std', 'np.std', (['test_scores'], {'axis': '(1)'}), '(test_scores, axis=1)\n', (1841, 1862), True, 'import numpy as np\n'), ((1867, 1965), 'matplotlib.pyplot.plot', 'plt.plot', (['param_range', 'train_mean'], {'color': '"""r"""', 'marker': '"""o"""', 'markersize': '(5)', 'label': '"""Training score"""'}), "(param_range, train_mean, color='r', marker='o', markersize=5,\n    label='Training score')\n", (1875, 1965), True, 'import matplotlib.pyplot as plt\n'), ((1966, 2070), 'matplotlib.pyplot.fill_between', 'plt.fill_between', (['param_range', '(train_mean + train_std)', '(train_mean - train_std)'], {'alpha': '(0.15)', 'color': '"""r"""'}), "(param_range, train_mean + train_std, train_mean -\n    train_std, alpha=0.15, color='r')\n", (1982, 2070), True, 'import matplotlib.pyplot as plt\n'), ((2071, 2186), 'matplotlib.pyplot.plot', 'plt.plot', (['param_range', 'test_mean'], {'color': '"""g"""', 'linestyle': '"""--"""', 'marker': '"""s"""', 'markersize': '(5)', 'label': '"""Validation score"""'}), "(param_range, test_mean, color='g', linestyle='--', marker='s',\n    markersize=5, label='Validation score')\n", (2079, 2186), True, 'import matplotlib.pyplot as plt\n'), ((2187, 2287), 'matplotlib.pyplot.fill_between', 'plt.fill_between', (['param_range', '(test_mean + test_std)', '(test_mean - test_std)'], {'alpha': '(0.15)', 'color': '"""g"""'}), "(param_range, test_mean + test_std, test_mean - test_std,\n    alpha=0.15, color='g')\n", (2203, 2287), True, 'import matplotlib.pyplot as plt\n'), ((2288, 2302), 'matplotlib.pyplot.grid', 'plt.grid', (['(True)'], {}), '(True)\n', (2296, 2302), True, 'import matplotlib.pyplot as plt\n'), ((2308, 2325), 'matplotlib.pyplot.xscale', 'plt.xscale', (['"""log"""'], {}), "('log')\n", (2318, 2325), True, 'import matplotlib.pyplot as plt\n'), ((2330, 2352), 'matplotlib.pyplot.legend', 'plt.legend', ([], {'loc': '"""best"""'}), "(loc='best')\n", (2340, 2352), True, 'import matplotlib.pyplot as plt\n'), ((2358, 2381), 'matplotlib.pyplot.xlabel', 'plt.xlabel', (['"""Parameter"""'], {}), "('Parameter')\n", (2368, 2381), True, 'import matplotlib.pyplot as plt\n'), ((2387, 2406), 'matplotlib.pyplot.ylabel', 'plt.ylabel', (['"""Score"""'], {}), "('Score')\n", (2397, 2406), True, 'import matplotlib.pyplot as plt\n'), ((2412, 2426), 'matplotlib.pyplot.ylim', 'plt.ylim', (['ylim'], {}), '(ylim)\n', (2420, 2426), True, 'import matplotlib.pyplot as plt\n'), ((379, 394), 'matplotlib.pyplot.ylim', 'plt.ylim', (['*ylim'], {}), '(*ylim)\n', (387, 394), True, 'import matplotlib.pyplot as plt\n')]