sklearn neural_net & export to js !

Category:

# -*- coding: utf-8 -*-
"""
Created on Mon Jan 21 01:30:05 2019

@author: K
"""

from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_breast_cancer
cancer = load_breast_cancer()
print(cancer['data'].shape)
X = cancer['data']
y = cancer['target']

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y)

#from sklearn.preprocessing import StandardScaler
from sklearn import preprocessing
#scaler = StandardScaler()
# Fit only to the training data
X_train = preprocessing.scale(X_train)
#X_train = preprocessing.normalize(X_train)
X_test = preprocessing.scale(X_test)

from sklearn.neural_network import MLPClassifier
mlp = MLPClassifier(hidden_layer_sizes=(30,30,30))
mlp.fit(X_train,y_train)

predictions = mlp.predict(X_test)
from sklearn.metrics import classification_report,confusion_matrix
print(confusion_matrix(y_test,predictions))
print(classification_report(y_test,predictions))


from sklearn_porter import Porter
porter = Porter(mlp, language='js')
#porter nom_pkl --js --pipe > estimator.js
output = porter.export(embed_data=True)
#print(output)