2017-09-08 50 views
0

給定n樣本,m功能和使用[sklearn.neural_network.MLPClassifier][1]的數據集,如何設置hidden_layer_sizesm輸入開頭?例如,我明白如果hidden_layer_sizes= (10,10)這意味着有10個神經元(即單位)中的每一個都有2個隱藏層,但我不知道這是否也暗示了10個輸入。如何設置sklearn MLPClassifier輸入神經元的數量?

謝謝

回答

1

這個分類器/迴歸器,如實現,當調用fit時自動執行此操作。

這可以在代碼here中看到。

摘錄:

n_samples, n_features = X.shape 

# Ensure y is 2D 
if y.ndim == 1: 
    y = y.reshape((-1, 1)) 

self.n_outputs_ = y.shape[1] 

layer_units = ([n_features] + hidden_layer_sizes + 
       [self.n_outputs_]) 

你看,你可能給出hidden_layer_sizes由內.fit()你的數據定義層維度包圍。這是什麼原因,簽名讀起來就像this 2 !:

參數減法

hidden_layer_sizes : tuple, length = n_layers - 2, default (100,) 

The ith element represents the number of neurons in the ith hidden layer. 
+0

謝謝您的答覆。所以會有輸入層的'n_features'神經元內部應用+輸出一個神經元! – Kris

+1

是的。它的可視化[here](http://scikit-learn.org/stable/modules/neural_networks_supervised.html#multi- layer-perceptron)。 – sascha