Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions multilayer_perceptron/multilayer_perceptron.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

from abc import ABCMeta, abstractmethod
from scipy.optimize import fmin_l_bfgs_b
from scipy.special import expit

from sklearn.base import BaseEstimator, ClassifierMixin, RegressorMixin
from sklearn.externals import six
from sklearn.preprocessing import LabelBinarizer
from sklearn.utils import gen_even_slices
from sklearn.utils import shuffle
from sklearn.utils import atleast2d_or_csr, check_random_state, column_or_1d
from sklearn.utils.extmath import logistic_sigmoid, safe_sparse_dot
from sklearn.utils.extmath import safe_sparse_dot


def _identity(X):
Expand Down Expand Up @@ -108,7 +109,7 @@ class BaseMultilayerPerceptron(six.with_metaclass(ABCMeta, BaseEstimator)):
"""
activation_functions = {
'tanh': _tanh,
'logistic': logistic_sigmoid,
'logistic': expit,
'softmax': _softmax
}
derivative_functions = {
Expand Down Expand Up @@ -213,7 +214,7 @@ def _init_param(self):
self.output_func = _softmax
# output for binary class and multi-label
else:
self.output_func = logistic_sigmoid
self.output_func = expit

def _init_t_eta_(self):
"""Initialize iteration counter attr ``t_``"""
Expand Down Expand Up @@ -751,7 +752,7 @@ def predict(self, X):
scores = self.decision_function(X)

if len(scores.shape) == 1 or self.multi_label is True:
scores = logistic_sigmoid(scores)
scores = expit(scores)
results = (scores > 0.5).astype(np.int)

if self.multi_label:
Expand Down Expand Up @@ -795,7 +796,7 @@ def predict_proba(self, X):
scores = self.decision_function(X)

if len(scores.shape) == 1:
scores = logistic_sigmoid(scores)
scores = expit(scores)
return np.vstack([1 - scores, scores]).T
else:
return _softmax(scores)
Expand Down