1
$\begingroup$

Well, it might seem ridiculous but I was just thinking whether it is possible to have these two methods simultaneously or not. I ran the code and faced an error, but in theory it doesn't seem impossible to me. But I couldn't find anything similar. Could you please enlighten me?

Here's the code that I tried to run k-fold cross validation with Drop out in layers and failed with the following error

#Using kfold cross validation in order to evaluate the ANN
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import cross_val_score

#Adding grid search for parameter tuning
from sklearn.model_selection import GridSearchCV

from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout

def build_classifier():
    classifier = Sequential()
    classifier.add(Dense(output_dim=6, init= 'uniform', activation='relu', input_dim=11))
    classifier.add(Dropout(p=0.1))
    classifier.add(Dense(output_dim=6, init= 'uniform', activation='relu'))
    classifier.add(Dropout(p=0.1))
    classifier.add(Dense(output_dim=1, init='uniform', activation="sigmoid"))
    classifier.add(Dropout(p=0.1))
    classifier.compile(optimizer='adam', loss="binary_crossentropy", metrics=['accuracy'])
    return classifier
classifier = KerasClassifier(build_fn = build_classifier, batch_size=10, nb_epoch = 100)
accuracies = cross_val_score(estimator = classifier, X=x_train, y = y_train, cv=10, n_jobs = -1) #cv is the number of folds

error:

UnboundLocalError: local variable 'a' referenced before assignment

While there is no "a" there!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.