<jupyter_start><jupyter_text>---**This Jupyter notebook contains the code to create the data visualizations for the article "Model evaluation, model selection, and algorithm selection in machine learning - Part I"at http://sebastianraschka.com/blog/2016/model-evaluation-selection-part1.html.**---<jupyter_code>%matplotlib inline<jupyter_output><empty_output><jupyter_text>Iris Feature by Class Distribution in Random Subsampling<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from mlxtend.data import iris_data
from mlxtend.preprocessing import shuffle_arrays_unison

X, y = iris_data()

X, y = shuffle_arrays_unison([X, y], random_seed=123)
X_train, X_test = X[:100], X[100:150]
y_train, y_test = y[:100], y[100:150]
np.bincount(y)
np.bincount(y_train)
np.bincount(y_test)
df = pd.DataFrame(X)
df['class'] = y

df_train = pd.DataFrame(X_train)
df_train['class'] = y_train

df_test = pd.DataFrame(X_test)
df_test['class'] = y_test
def stackhist(x, y, **kws):
    grouped = pd.groupby(x, y)
    data = [d for _, d in grouped]
    labels = [l for l, _ in grouped]
    plt.hist(data, histtype="barstacked", 
             label=labels, alpha=0.8, normed=True,
             bins=np.arange(4.0, 8.1, 0.25))
    plt.ylim([0, 0.6])
    plt.xlim([4, 8])
    plt.xlabel('Sepal Width [cm]')
    plt.ylabel('Frequency')

with plt.style.context('fivethirtyeight'):    
    
    stackhist(df[0], df['class'])
    #plt.legend(['Setosa', 'Virginica', 'Versicolor'], fontsize=12)
    plt.title('All')
    plt.tight_layout()
    plt.savefig('./all.svg')
    plt.show()    

    stackhist(df_train[0], df_train['class'])
    plt.title('Train')
    plt.tight_layout()
    #plt.savefig('./train.svg')
    plt.show()    

    stackhist(df_test[0], df_test['class'])
    plt.title('Test')
    plt.tight_layout()
    #plt.savefig('./test.svg')
    plt.show() 
    
    """
    fig = plt.figure()
    figlegend = plt.figure(figsize=(3,4))
    ax = fig.add_subplot(111)
    lines = ax.plot(range(10), np.random.randn(10), range(10), np.random.randn(10), np.random.randn(10), range(10),)
    figlegend.legend(lines, ['Setosa', 'Virginica', 'Versicolor'], 'center')
    fig.show()
    figlegend.show()
    figlegend.savefig('legend.svg')
    """<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16323851203501094, 'fraction_numerical': 0.027133479212253828, 'mean_word_length': 3.9912663755458517, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '146943', 'license': 'MIT', 'n_tokens_mistral': 912, 'n_tokens_neox': 850, 'n_words': 166, 'path': 'pattern-classification/data_viz/model-evaluation-articles/iris-random-dist.ipynb', 'repo_name': 'gopala-kr/ds-notebooks', 'size': '2285'}