-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Serialization error when using parallelism in cross_val_score with GridSearchCV and a custom estimator #12413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I had the same issue a few days ago with a custom estimator. Thanks for the minimal example @TomDLT |
Duplicate of #12250 |
hii thank you for posting this but if we put n-jobs = 1, it will take much more right? |
You should not have such an error with the last version of scikit-learn. Which version are you using? |
The scikit-learn version is 0.20.0. |
This is solved in versions > 0.20.1. |
I really appreciate your help thank u After checking both the version i am still getting error . the error is following |
I am still encountering this problem when using either scikit-learn versions 0.20.1 or 0.20.2. |
@elayden could you post a reproducible example of the error? |
Here I am sharing my complete code: from sklearn.model_selection import cross_val_score from keras.models import Sequential from keras.layers import Dense def build_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)` I have checked for both scikit-learn versions 0.20.1 and 0.20.2. |
I also have this problem. Python=3.6 and scikit-learn=0.20.2 |
@sanketchavan08 I tried code on Windows and it did not work. I changed to use it on Ubuntu and it well done. But it just uses CPU not GPU, may be it does not support GPU for ANN training |
I also have this problem on Window 7 even if I am running with CPUs. |
I also have this problem using: but |
Could you please open a new issue with a reproducible example? The error seems to concern only Windows and custom estimators implemented using Keras whereas the original issue was concerning any platform and any custom estimator |
My problem is the same example explained in previous comments, and yes, I'm running a 64-bit Windows 10 and using keras. My lines of code are: import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
dataset = pd.read_csv('example.csv')
X = dataset.iloc[:, 3:13].values
y = dataset.iloc[:, 13].values
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X_1 = LabelEncoder()
X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])
labelencoder_X_2 = LabelEncoder()
X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])
onehotencoder = OneHotEncoder(categorical_features = [1])
X = onehotencoder.fit_transform(X).toarray()
X = X[:, 1:]
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import cross_val_score
from keras.models import Sequential
from keras.layers import Dense
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) Error: accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10, n_jobs = -1)
Traceback (most recent call last):
File "<ipython-input-4-cc51c2d2980a>", line 1, in <module>
accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10, n_jobs = -1)
File "C:\Users\Richar\Anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 402, in cross_val_score
error_score=error_score)
File "C:\Users\Richar\Anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 240, in cross_validate
for train, test in cv.split(X, y, groups))
File "C:\Users\Richar\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py", line 930, in __call__
self.retrieve()
File "C:\Users\Richar\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py", line 833, in retrieve
self._output.extend(job.get(timeout=self.timeout))
File "C:\Users\Richar\Anaconda3\lib\site-packages\sklearn\externals\joblib\_parallel_backends.py", line 521, in wrap_future_result
return future.result(timeout=timeout)
File "C:\Users\Richar\Anaconda3\lib\concurrent\futures\_base.py", line 432, in result
return self.__get_result()
File "C:\Users\Richar\Anaconda3\lib\concurrent\futures\_base.py", line 384, in __get_result
raise self._exception
BrokenProcessPool: A task has failed to un-serialize. Please ensure that the arguments of the function are all picklable. I'm using: |
Thanks for the details @rfernandezv. What I meant is that the original issue, described in the top comment is not the same as the one you describe, although similar. The original issue was solved and closed. It would be better to open a new issue with your error (related to Windows, Keras and joblib). |
Thanks @albertcthomas. I opened a new issue #13228 |
using n_jobs = 1 , solved the error on windows 10 ,python 3.5 |
you need to install the joblib package. |
I know, but I wanted to fix the error with |
import os |
I get the same error with Python 3.7.3, and Sklearn 0.20.2 under Windows 10. None of the above worked for me. Can this issue be solved somehow? |
What does it do @llc8888? |
Having same issues with sklearn v0.20.2 Hope it helps. |
Uh oh!
There was an error while loading. Please reload this page.
Minimal example:
Full traceback in details.
Interestingly, it does not fail when:
cross_val_score
withn_jobs=1
.cross_val_score
directly ondummy
, withoutGridSearchCV
.LogisticRegression
, or even the sameDummy
custom classifier but imported from another file.This is a joblib 0.12 issue, different from #12289 or #12389. @ogrisel @tomMoral
The text was updated successfully, but these errors were encountered: