首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在L1中添加MLPClaccifier正则化?

如何在L1中添加MLPClaccifier正则化?
EN

Stack Overflow用户
提问于 2022-10-04 15:01:37
回答 1查看 127关注 0票数 0

我想在sklearn的L1中实现MLPClassifier的正则化。下面是我的代码,alpha=0.0001是L2正则化的默认代码。我想使用L1正则化而不是L2。

代码语言:javascript
复制
# evaluate a Neural Networks with ReLU and L1 norm regularization

from numpy import mean
from numpy import std
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.neural_network import MLPClassifier

# prepare the cross-validation procedure (10X10)
cv = KFold(n_splits=10, random_state=1, shuffle=True)

# create model L2 Regularization ["alpha" here is used as a hyperparamter for L2 
regularization]
model = MLPClassifier(alpha=0.0001, hidden_layer_sizes=(100,), activation='relu', 
solver='adam')

# evaluate model
scores = cross_val_score(model, X, y, scoring='accuracy', cv=cv, n_jobs=-1)

# report performance
print('Accuracy: %.3f (%.3f)' % (mean(scores), std(scores)))
EN

回答 1

Stack Overflow用户

发布于 2022-10-05 19:56:09

这是不可能的。Scikit--关于支持神经网络有很多很长时间的讨论,并决定不支持它。它们提供极其基本/僵化的实现,仅此而已。对于定制,你需要看看角,tf,火炬,贾克斯等。

即使scikit学习本身也推荐该https://scikit-learn.org/stable/related_projects.html#related-projects的其他库。

代码语言:javascript
复制
Deep neural networks etc.

nolearn A number of wrappers and abstractions around existing neural network libraries

Keras High-level API for TensorFlow with a scikit-learn inspired API.

lasagne A lightweight library to build and train neural networks in Theano.

skorch A scikit-learn compatible neural network library that wraps PyTorch.

scikeras provides a wrapper around Keras to interface it with scikit-learn. SciKeras is the successor of tf.keras.wrappers.scikit_learn.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73949892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档