只是想知道是否有人对Mlens python软件包有过任何经验,并使用神经网络(前馈密集型)作为最终的元学习者?
下面是一些代码来说明:
ensemble = SuperLearner(scorer=accuracy_score, verbose=2)
ensemble.add([RandomForestClassifier(), SVC()])
ensemble.add_meta(INSERT_KERAS_MODEL_HERE())
ensemble.fit(preprocesser.fit_transform(X_train), y_train)
preds = ensemble.predict(preprocesser.transform(X_test))
print("Fit data:\n%r" % ensemble.data)
print("Prediction score: %.3f" % accuracy_score(preds, y_test))
理想情况下,Keras模型看起来像这样吗?
def FFDNN():
DNN = Sequential()
DNN.add(Dense(128, activation='relu', input_dim=1414))
DNN.add(Dropout(0.2))
DNN.add(Dense(64, activation='relu'))
DNN.add(Dropout( 0.1))
DNN.add(Dense( 36, activation='relu'))
DNN.add(Dense(1,activation='sigmoid'))
DNN.compile(loss = 'binary_crossentropy',
optimizer ='adam', metrics =['accuracy'])
return DNN
early_stopping = EarlyStopping(monitor='val_loss', patience=100)
checkpoint = ModelCheckpoint(filepath='best_model.h5',
monitor='val_loss', save_best_only=True)
pipe = Pipeline(steps=[('preprocessor', preprocesser),
('classifier', KerasClassifier(FFDNN, epochs=600, batch_size=50,
verbose=1, callbacks = [early_stopping,checkpoint],
validation_split=0.2))])
#training Keras model
pipe.fit(X_train, y_train)
那么最终产品会这样工作吗?
def FFDNN():
DNN = Sequential()
DNN.add(Dense(128, activation='relu', input_dim=input_dim))
DNN.add(Dropout(0.2))
DNN.add(Dense(64, activation='relu'))
DNN.add(Dropout( 0.1))
DNN.add(Dense( 36, activation='relu'))
DNN.add(Dense(1,activation='sigmoid'))
DNN.compile(loss = 'binary_crossentropy',
optimizer ='adam', metrics =['accuracy'])
return DNN
ensemble = SuperLearner(scorer=accuracy_score)
ensemble.add([RandomForestClassifier(), LogisticRegression()])
ensemble.add([LogisticRegression(), SVC()])
ensemble.add_meta(KerasClassifier(FFDNN, epochs=600, batch_size=50, verbose=1))
ensemble.fit(preprocesser.fit_transform(X_train), y_train)
preds = ensemble.predict(preprocesser.transform(X_test))
print("Fit data:\n%r" % ensemble.data)
print("Prediction score: %.3f" % accuracy_score(preds, y_test))
随时分享一些示例,我很好奇是否可以使用Mlens软件包,还是我应该手动实现它?