我正在使用scikit-multilearn和Keras包装器来制作模型,如代码中所述:
KERAS_PARAMS = dict(epochs=1, batch_size=100, verbose=1)
classifier = LabelSpacePartitioningClassifier(
classifier = LabelPowerset(
classifier=Keras(multimodel, True, KERAS_PARAMS),
require_dense = [False, True]
),
require_dense = [True, True],
clusterer = FixedLabelSpaceClusterer(clusters=my_cluster)
)
我的多模型是使用TensorFlow / Keras构建的简单神经网络:
def multimodel(input_dim, output_dim):
model = Sequential()
model.add(Dense(10, input_dim=input_dim, activation='relu'))
model.add(Dropout(0.1))
model.add(Dense(10, activation=tf.keras.layers.LeakyReLU()))
model.add(BatchNormalization())
model.add(Dense(10, activation=tf.keras.layers.PReLU()))
model.add(Dropout(0.1))
model.add(Dense(10, activation='relu'))
model.add(BatchNormalization())
model.add(Dense(10, activation=tf.keras.layers.LeakyReLU()))
model.add(Dropout(0.1))
model.add(Dense(output_dim, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy', tfa.metrics.FBetaScore(output_dim)])
return model
但是在训练模型之后,我无法获得权重。我已经尝试过类似的事情:
joblib.dump(classifier.get_params(), 'model.joblib')
我还尝试将整个模型包装在GridSearhCV中并保存best_estimator_
,但没有用。