I am trying to create a hard voting ensemble of three neural networks. I've already converted them to Keras Classifiers.
Here is the code:

from tensorflow.keras.layers import Input, Average
from sklearn.ensemble import VotingClassifier
from sklearn.metrics import accuracy_score
from keras.wrappers.scikit_learn import KerasClassifier

#load models
model1 = keras.models.load_model('/content/drive/MyDrive/Glomerulimodels/...')
model2 = keras.models.load_model('/content/drive/MyDrive/Glomerulimodels/...')
model3 = keras.models.load_model('/content/drive/MyDrive/Glomerulimodels/...')

model1 = KerasClassifier(model1)
model2 = KerasClassifier(model2)
model3 = KerasClassifier(model3)

model1._estimator_type = "classifier"
model2._estimator_type = "classifier"
model3._estimator_type = "classifier"

voting = VotingClassifier(estimators=[('model1', model1), ('model2', model2), ('model3', model3)], voting='hard')

voting.fit(X_train, y_train)
predicted = voting.predict(X_test)
accuracy = accuracy_score(predicted, y_test)

It runs for a bit then I get this error: enter image description here



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.