gpt4 book ai didi

machine-learning - scikit learn如何实现输出层

转载 作者:行者123 更新时间:2023-11-30 08:46:11 25 4
gpt4 key购买 nike

  1. 在 scikit learn 中,输出层有多少个神经元?如前所述here ,你只能指定隐藏层的大小及其神经元,而不能指定输出层,因此我不确定 scikit learn 是如何实现输出层的。
  2. 对于只有单个神经元的输出层使用 softmax 激活函数是否有意义?

最佳答案

测试:

设置:

In [227]: %paste
clf = MLPClassifier()

m = 10**3
n = 64

df = pd.DataFrame(np.random.randint(100, size=(m, n))).add_prefix('x') \
.assign(y=np.random.choice([-1,1], m))


X_train, X_test, y_train, y_test = \
train_test_split(df.drop('y',1), df['y'], test_size=0.2, random_state=33)

clf.fit(X_train, y_train)
## -- End pasted text --
Out[227]:
MLPClassifier(activation='relu', alpha=0.0001, batch_size='auto', beta_1=0.9,
beta_2=0.999, early_stopping=False, epsilon=1e-08,
hidden_layer_sizes=(100,), learning_rate='constant',
learning_rate_init=0.001, max_iter=200, momentum=0.9,
nesterovs_momentum=True, power_t=0.5, random_state=None,
shuffle=True, solver='adam', tol=0.0001, validation_fraction=0.1,
verbose=False, warm_start=False)

输出数量:

In [229]: clf.n_outputs_
Out[229]: 1

层数:

In [228]: clf.n_layers_
Out[228]: 3

求解器运行的迭代次数:

In [230]: clf.n_iter_
Out[230]: 60
<小时/>

这里是 source code 的摘录其中输出层的激活函数将被选择:

    # Output for regression
if not is_classifier(self):
self.out_activation_ = 'identity'
# Output for multi class
elif self._label_binarizer.y_type_ == 'multiclass':
self.out_activation_ = 'softmax'
# Output for binary class and multi-label
else:
self.out_activation_ = 'logistic'

更新: MLPClassifier binarizes (in a one-vs-all fashion) labels internaly, so logistic regression should work well also with labels that are differ from [0,1] :

    if not incremental:
self._label_binarizer = LabelBinarizer()
self._label_binarizer.fit(y)
self.classes_ = self._label_binarizer.classes_

关于machine-learning - scikit learn如何实现输出层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47359784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com