sklearn: Set the valute to the attribute out_activation_ to 'logistic'

Question:

I need to set the attribute activation_out = ‘logistic’ in a MLPRegressor of sklearn. It is supposed that this attribute can take the names of the relevant activation functions (‘relu’,’logistic’,’tanh’ etc). The problem is that I cannot find the way that you can control this attribute and set it to the preferred functions. Please, if someone has faced this problem before or knows something more, I want some help.

I have tried to set attribute to MLPRegressor(), error. I have tried with the method set_params(), error. I have tried manually to change it through Variable Explorer, error. Finally, I used MLPName.activation_out = ‘logistic’ but again when I used fit() method it changed to ‘identity’.
CODE:

X_train2, X_test2, y_train2,y_test2 = 
train_test_split(signals_final,masks,test_size=0.05,random_state = 
17)
scaler2 = MinMaxScaler()
X_train2 = scaler.fit_transform(X_train2)
X_test2 = scaler.transform(X_test2)

MatchingNetwork = MLPRegressor(alpha = 1e-15,hidden_layer_sizes= 
(300,)                          
,random_state=1,max_iter=20000,activation='logistic',batch_size=64)
MLPRegressor().out_activation_ = 'logistic'
Asked By: Evangelos Galaris

||

Answers:

You cannot. The output activation is determined by the problem type at fit time. For regression, the identity activation is used; see the User Guide.

Here is the relevant bit of source code. You might be able to hack it by fitting one iteration, changing the attribute, then using partial_fit, since then this _initialize method won’t be called again; but it’s likely to break when back-propogating.

Generally I think the sklearn neural networks aren’t designed to be super flexible: there are other packages that play that role, are more efficient (use GPUs), etc.

Answered By: Ben Reiniger