我想在sklearn的L1中实现MLPClassifier的正则化。下面是我的代码,alpha=0.0001是L2正则化的默认代码。我想使用L1正则化而不是L2。
# 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)))发布于 2022-10-05 19:56:09
这是不可能的。Scikit--关于支持神经网络有很多很长时间的讨论,并决定不支持它。它们提供极其基本/僵化的实现,仅此而已。对于定制,你需要看看角,tf,火炬,贾克斯等。
即使scikit学习本身也推荐该https://scikit-learn.org/stable/related_projects.html#related-projects的其他库。
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.https://stackoverflow.com/questions/73949892
复制相似问题