<jupyter_start><jupyter_text>iris  data loading data: 'iris.data.csv'<jupyter_code>import pandas as pd
import numpy as np
dt = pd.read_csv('../data/iris.data.csv')
dt.head()
dt.shape<jupyter_output><empty_output><jupyter_text>random shuffle<jupyter_code>from sklearn.utils import shuffle
dt = pd.DataFrame(shuffle(dt))<jupyter_output><empty_output><jupyter_text>single validation: 67% + 33%<jupyter_code>threshold = 100<jupyter_output><empty_output><jupyter_text>classification<jupyter_code>from sklearn.metrics import accuracy_score

def classification(clf):
    clf.fit(dt.iloc[:threshold,:4], dt.iloc[:threshold,4])
    preds = pd.Series(clf.predict(dt.iloc[threshold:,:4]), name='preds')
    reals = pd.Series(dt.iloc[threshold:,4],name='reals')
    reals.index = range(50)
    print('acc:', accuracy_score(reals, preds))
    print()
    print(pd.crosstab(reals, preds))
    print()<jupyter_output><empty_output><jupyter_text>Linear Perceptron<jupyter_code>%%time
from sklearn.linear_model import Perceptron
classification(Perceptron())<jupyter_output>acc: 0.84

preds            Iris-setosa  Iris-versicolor  Iris-virginica
reals                                                        
Iris-setosa               14                1               0
Iris-versicolor            0               17               1
Iris-virginica             0                6              11

CPU times: user 67.7 ms, sys: 14.3 ms, total: 81.9 ms
Wall time: 79.9 ms<jupyter_text>Multi-Layer Perceptron<jupyter_code>%%time
from sklearn.neural_network import MLPClassifier
classification(MLPClassifier(hidden_layer_sizes=(25,)))<jupyter_output>acc: 0.9

preds            Iris-setosa  Iris-versicolor  Iris-virginica
reals                                                        
Iris-setosa               15                0               0
Iris-versicolor            0               13               5
Iris-virginica             0                0              17

CPU times: user 112 ms, sys: 558 µs, total: 112 ms
Wall time: 109 ms<jupyter_text>Deep Learning<jupyter_code>%%time
classification(MLPClassifier(hidden_layer_sizes=(25,10)))<jupyter_output>acc: 0.96

preds            Iris-setosa  Iris-versicolor  Iris-virginica
reals                                                        
Iris-setosa               15                0               0
Iris-versicolor            0               16               2
Iris-virginica             0                0              17

CPU times: user 137 ms, sys: 0 ns, total: 137 ms
Wall time: 133 ms
{'fraction_non_alphanumeric': 0.09188118811881188, 'fraction_numerical': 0.038415841584158415, 'mean_word_length': 2.0360576923076925, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '423281', 'license': 'MIT', 'n_tokens_mistral': 885, 'n_tokens_neox': 799, 'n_words': 160, 'path': 'codes/nn-sklearn.ipynb', 'repo_name': 'gebakx/ml-games', 'size': '2525'}