| 
4 | 4 | # License: Simple BSD  | 
5 | 5 | 
 
  | 
6 | 6 | """  | 
7 |  | -The :mod:`sklearn.neural_networks.elm` module implements the  | 
 | 7 | +The :mod:`elm` module implements the  | 
8 | 8 | Extreme Learning Machine Classifiers and Regressors (ELMClassifier,  | 
9 | 9 | ELMRegressor, SimpleELMRegressor, SimpleELMClassifier).  | 
10 | 10 | 
  | 
 | 
24 | 24 | from abc import ABCMeta, abstractmethod  | 
25 | 25 | 
 
  | 
26 | 26 | import numpy as np  | 
 | 27 | +from scipy.linalg import pinv2  | 
27 | 28 | 
 
  | 
28 | 29 | from sklearn.utils import as_float_array  | 
 | 30 | +from sklearn.utils.extmath import safe_sparse_dot  | 
29 | 31 | from sklearn.base import BaseEstimator, ClassifierMixin, RegressorMixin  | 
30 | 32 | from sklearn.preprocessing import LabelBinarizer  | 
31 |  | -from sklearn.linear_model import LinearRegression  | 
32 | 33 | 
 
  | 
33 | 34 | from random_hidden_layer import SimpleRandomHiddenLayer  | 
34 | 35 | 
 
  | 
@@ -140,19 +141,17 @@ def __init__(self,  | 
140 | 141 | 
 
  | 
141 | 142 |         super(ELMRegressor, self).__init__(hidden_layer, regressor)  | 
142 | 143 | 
 
  | 
 | 144 | +        self.coefs_ = None  | 
143 | 145 |         self.fitted_ = False  | 
144 | 146 |         self.hidden_activations_ = None  | 
145 |  | -        self._lin_reg = LinearRegression(copy_X=False,  | 
146 |  | -                                         normalize=False,  | 
147 |  | -                                         fit_intercept=False)  | 
148 | 147 | 
 
  | 
149 | 148 |     def _fit_regression(self, y):  | 
150 | 149 |         """  | 
151 | 150 |         fit regression using internal linear regression  | 
152 | 151 |         or supplied regressor  | 
153 | 152 |         """  | 
154 | 153 |         if (self.regressor is None):  | 
155 |  | -            self._lin_reg.fit(self.hidden_activations_, y)  | 
 | 154 | +            self.coefs_ = safe_sparse_dot(pinv2(self.hidden_activations_), y)  | 
156 | 155 |         else:  | 
157 | 156 |             self.regressor.fit(self.hidden_activations_, y)  | 
158 | 157 | 
 
  | 
@@ -189,7 +188,7 @@ def fit(self, X, y):  | 
189 | 188 |     def _get_predictions(self, X):  | 
190 | 189 |         """get predictions using internal least squares/supplied regressor"""  | 
191 | 190 |         if (self.regressor is None):  | 
192 |  | -            preds = self._lin_reg.predict(self.hidden_activations_)  | 
 | 191 | +            preds = safe_sparse_dot(self.hidden_activations_, self.coefs_)  | 
193 | 192 |         else:  | 
194 | 193 |             preds = self.regressor.predict(self.hidden_activations_)  | 
195 | 194 | 
 
  | 
 | 
0 commit comments