<jupyter_start><jupyter_text>sklearn-porterRepository: [https://github.com/nok/sklearn-porter](https://github.com/nok/sklearn-porter) MLPClassifierDocumentation: [sklearn.neural_network.MLPClassifier](http://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPClassifier.html)<jupyter_code>import sys
sys.path.append('../../../../..')<jupyter_output><empty_output><jupyter_text>Load data<jupyter_code>from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.utils import shuffle

iris_data = load_iris()
X = iris_data.data
y = iris_data.target

X = shuffle(X, random_state=0)
y = shuffle(y, random_state=0)

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.4, random_state=5)

print(X_train.shape, y_train.shape)
print(X_test.shape, y_test.shape)<jupyter_output>((90, 4), (90,))
((60, 4), (60,))<jupyter_text>Train classifier<jupyter_code>from sklearn.neural_network import MLPClassifier

clf = MLPClassifier(activation='relu', hidden_layer_sizes=50,
                    max_iter=500, alpha=1e-4, solver='sgd',
                    tol=1e-4, random_state=1, learning_rate_init=.1)
clf.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Transpile classifier<jupyter_code>from sklearn_porter import Porter

porter = Porter(clf, language='js')
output = porter.export()

print(output)<jupyter_output>var MLPClassifier = function(hidden, output, layers, weights, bias) {

    this.hidden = hidden.toUpperCase();
    this.output = output.toUpperCase();
    this.network = new Array(layers.length + 1);
    for (var i = 0, l = layers.length; i < l; i++) {
        this.network[i + 1] = new Array(layers[i]).fill(0.);
    }
    this.weights = weights;
    this.bias = bias;

    var compute = function(activation, v) {
        switch (activation) {
            case 'LOGISTIC':
                for (var i = 0, l = v.length; i < l; i++) {
                    v[i] = 1. / (1. + Math.exp(-v[i]));
                }
                break;
            case 'RELU':
                for (var i = 0, l = v.length; i < l; i++) {
                    v[i] = Math.max(0, v[i]);
                }
                break;
            case 'TANH':
                for (var i = 0, l = v.length; i < l; i++) {
                    v[i] = Math.tanh(v[i]);
                }
                break;
            case 'SOFTMAX':[...]<jupyter_text>Run classification in JavaScript<jupyter_code># Save classifier:
# with open('MLPClassifier.js', 'w') as f:
#     f.write(output)

# Run classification:
# if hash node 2/dev/null; then
#     node MLPClassifier.js 1 2 3 4
# fi<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1447811447811448, 'fraction_numerical': 0.01533857089412645, 'mean_word_length': 2.9036496350364964, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '351331', 'license': 'MIT', 'n_tokens_mistral': 996, 'n_tokens_neox': 937, 'n_words': 182, 'path': 'examples/estimator/classifier/MLPClassifier/js/basics.pct.ipynb', 'repo_name': 'karoka/sklearn-porter', 'size': '2673'}