【问题标题】:How to set up the number of inputs neurons in sklearn MLPClassifier?如何在 sklearn MLPClassifier 中设置输入神经元的数量?
【发布时间】:2018-02-17 21:04:14
【问题描述】:

给定一个包含n 样本、m 特征的数据集,并使用[sklearn.neural_network.MLPClassifier][1],我如何设置hidden_layer_sizes 以从m 输入开始?例如,我知道如果hidden_layer_sizes= (10,10) 表示 10 个神经元(即单元)中的每一个有 2 个隐藏层,但我不知道这是否也意味着 10 个输入。

谢谢

【问题讨论】:

    标签: scikit-learn neural-network


    【解决方案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.
    

    【讨论】:

    • 感谢您的回复。所以会有一个内部应用的n_features神经元的输入层+一个用于输出的神经元!!
    • 是的。它被可视化了here
    猜你喜欢
    • 2016-12-04
    • 2018-10-20
    • 2019-05-01
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    • 2017-11-28
    相关资源
    最近更新 更多