Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most important features in MLPClassifier in Sklearn

I would like to know if there is any way to visualize or find the most important/contributing features after fitting a MLP classifier in Sklearn.

Simple example:

import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import LeaveOneOut
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import make_pipeline


data= pd.read_csv('All.csv', header=None)
X, y = data.iloc[0:, 0:249].values, data.iloc[0:,249].values

sc = StandardScaler()
mlc = MLPClassifier(activation = 'relu', random_state=1,nesterovs_momentum=True)
loo = LeaveOneOut()
pipe = make_pipeline(sc, mlc)

parameters = {"mlpclassifier__hidden_layer_sizes":[(168,),(126,),(498,),(166,)],"mlpclassifier__solver" : ('sgd','adam'), "mlpclassifier__alpha": [0.001,0.0001],"mlpclassifier__learning_rate_init":[0.005,0.001] }
clf = GridSearchCV(pipe, parameters,n_jobs= -1,cv = loo)
clf.fit(X, y)

model = clf.best_estimator_
print("the best model and parameters are the following: {} ".format(model))
like image 897
seralouk Avatar asked Jun 09 '17 14:06

seralouk


People also ask

What is Max ITER in MLPClassifier?

max_iter: It denotes the number of epochs. activation: The activation function for the hidden layers. solver: This parameter specifies the algorithm for weight optimization across the nodes.

What is the use of MLP Classifier?

Classification. Class MLPClassifier implements a multi-layer perceptron (MLP) algorithm that trains using Backpropagation. Currently, MLPClassifier supports only the Cross-Entropy loss function, which allows probability estimates by running the predict_proba method.

What is hidden layer sizes Sklearn?

By default in scikit-learn, it has a single hidden layer with 100 units. Hidden layer size is a tuple. The number of entries gives you the number of hidden layers, and each integer gives you the size of the layers. So here, this one has a single hidden layer of size 5.


1 Answers

Good question. The lack of interpretability of NN models is one pain the ML/NN community has been struggling with.

One recent approach that has been receiving attention is the LIME paper (Ribeiro et al, KDD'16). Here's a relevant excerpt from the abstract:

  • "In this work, we propose LIME, a novel explanation technique that explains the predictions of any classifier in an interpretable and faithful manner, by learning an interpretable model locally around the prediction".

There's also a GitHub repository (Python, yay!).

(If you do try LIME, please share your experience in the question comments..)

like image 67
Tomer Levinboim Avatar answered Sep 18 '22 18:09

Tomer Levinboim