cross_val_score() does not terminate
See original GitHub issueDescription
Using KerasClassifier for the estimator function of cross_value_score() as shown in the following code,
classifier=KerasClassifier(build_fn=build_classifier,batch_size=10,epochs=100) accuracies=cross_val_score(estimator=classifier,X=X_train,y=y_train,cv=10,n_jobs=-1)
only the following four lines are printed:
Epoch 1/100 Epoch 1/100 Epoch 1/100 Epoch 1/100
and the process does not terminate.
Steps/Code to Reproduce
import numpy as np
import keras
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import cross_val_score
def build_classifier():
classifier = Sequential()
classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))
classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))
classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
return classifier
classifier=KerasClassifier(build_fn=build_classifier,batch_size=10,epochs=100)
accuracies=cross_val_score(estimator=classifier,X=X_train,y=y_train,cv=10,n_jobs=-1)
Expected Results
The process should print all the epochs and continue until completion, then terminate.
Actual Results
Epoch 1/100 Epoch 1/100 Epoch 1/100 Epoch 1/100
Versions
import platform; print(platform.platform()) Linux-4.10.0-33-generic-x86_64-with-debian-stretch-sid
import sys; print(“Python”, sys.version) Python 3.6.2 |Anaconda custom (64-bit)| (default, Jul 20 2017, 13:51:32) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
import numpy; print(“NumPy”, numpy.version) NumPy 1.13.3
import scipy; print(“SciPy”, scipy.version) SciPy 0.19.1
import sklearn; print(“Scikit-Learn”, sklearn.version) Scikit-Learn 0.19.0
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:14 (5 by maintainers)
Top GitHub Comments
I have had issues that were similar to this, in the sense that the program would stop outputting things after a while. It turned out that some implementations (and/or algorithms) don’t like to be run in parallel when called from within a
BaseSearchCV
class (for me, it wasAdaBoostClassifier
andMLPClassifier
). Have you tried a single-threaded run by removingn_jobs = -1
from your function call tocross_val_score()
?@baharian and @amueller You are right, it is a parallelization issue. Thank you very much for your insights!
n_jobs=1
does the job. How can we improve and debug this parallelization issue?