<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(export_data=True)

print(output)<jupyter_output>if (typeof XMLHttpRequest === 'undefined') {
    var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
}

var MLPClassifier = function(jsonFile) {
    this.mdl = undefined;

    var promise = new Promise(function(resolve, reject) {
        var httpRequest = new XMLHttpRequest();
        httpRequest.onreadystatechange = function() {
            if (httpRequest.readyState === 4) {
                if (httpRequest.status === 200) {
                    resolve(JSON.parse(httpRequest.responseText));
                } else {
                    reject(new Error(httpRequest.status + ': ' + httpRequest.statusText));
                }
            }
        };
        httpRequest.open('GET', jsonFile, true);
        httpRequest.send();
    });

    // Return max index:
    var maxi = function(nums) {
        var index = 0;
        for (var i=0, l=nums.length; i < l; i++) {
            index = nums[i] > nums[index] ? i : index;
        }
        return index;
    };

    // Compute the ac[...]<jupyter_text>Run classification in JavaScript<jupyter_code># Save classifier:
# with open('MLPClassifier.js', 'w') as f:
#     f.write(output)

# Check model data:
# $ cat data.json

# Run classification:
# if hash node 2/dev/null; then
#     python -m SimpleHTTPServer 8877 & serve_pid=$!
#     node MLPClassifier.js http://127.0.0.1:8877/data.json 1 2 3 4
#     kill $serve_pid
# fi<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1343915343915344, 'fraction_numerical': 0.01798941798941799, 'mean_word_length': 3.5303514376996805, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 1, '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': '667860', 'license': 'MIT', 'n_tokens_mistral': 1019, 'n_tokens_neox': 962, 'n_words': 174, 'path': 'examples/estimator/classifier/MLPClassifier/js/basics_imported.pct.ipynb', 'repo_name': 'karoka/sklearn-porter', 'size': '2835'}