'YellowbrickTypeError for Keras Model: This estimator is not a classifier; try a regression or clustering score visualizer instead
I have the following Keras DNN model and have imported necessary Keras & Yellowbrick libraries:
optimizer = RMSprop(0.001)
finalDNNModel_wrap = KerasClassifier(build_fn=parkOptimalDNN(optimizer),
epochs=750,
batch_size=10, verbose=0)
finalDNNModel = Sequential()
finalDNNModel.add(Dense(32, input_dim=8, activation='relu'))
finalDNNModel.add(Dense(8, activation='relu'))
finalDNNModel.add(Dense(1, activation='sigmoid'))
#Compile the model
finalDNNModel.compile(loss='binary_crossentropy',optimizer=optimizer, metrics=['accuracy'])
# Fit & Evaluate on the independent validation data set
finalDNNModel.fit(X_pca_train,y_train,batch_size = 10,epochs = 750 , verbose = 0)
dnnPrediction = (finalDNNModel.predict(X_pca_validation) > 0.5).astype("int64")
dnnPredictProb = finalDNNModel.predict_proba(X_pca_validation)
I used the YellowBrick visualisation package for classification report as below:
classes = ["Not Parkinson", "Parkinson"]
pd.set_option('precision',2)
vizDNN = ClassificationReport(finalDNNModel,classes = classes,cmap="YlGnBu",is_fitted=True,
force_model=True,
title="DNN")
vizDNN.score(X_pca_validation, y_validation)
vizDNN.show()
It gives the error: "YellowbrickTypeError: This estimator is not a classifier; try a regression or clustering score visualizer instead!" Could somebody help
Solution 1:[1]
Try the following
# Import the wrap function and a Yellowbrick visualizer
from yellowbrick.contrib.wrapper import wrap
from yellowbrick.classifier import classification_report
# Instantiate the third party estimator and wrap it, optionally fitting it
finalDNNModel.fit(X_pca_train,y_train,batch_size = 10,epochs = 750 , verbose = 0)
model = wrap(finalDNNModel)
# Use the visualizer
oz = classification_report(model, X_train, y_train, X_test=X_test, y_test=y_test, support=True, is_fitted=True)
change train and test variables accordingly
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | larrywgray |