Repository: automl/auto-sklearn

Issue:
Exception: batch_size must be a positive integer
I was running the following two line script:

`automl = autosklearn.classification.AutoSklearnClassifier()`
`automl.fit(X_train, y_train)`

on the Pima Indians Diabetes binary classification dataset, and it ended hours later with the following error:



```
.
.
.
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
You are already timing task: index_run28
[WARNING] [2017-06-05 23:16:26,928:smac.intensification.intensification.Intensifier] Challenger was the same as the current incumbent; Skipping challenger
[WARNING] [2017-06-05 23:16:26,928:smac.intensification.intensification.Intensifier] Challenger was the same as the current incumbent; Skipping challenger
You are already timing task: index_run28
Traceback (most recent call last):
  File "auto-sklearn.py", line 21, in <module>
    predictions = cls.predict(X, Y)
  File "/usr/local/lib/python3.6/site-packages/autosklearn/estimators.py", line 421, in predict
    X, batch_size=batch_size, n_jobs=n_jobs)
  File "/usr/local/lib/python3.6/site-packages/autosklearn/estimators.py", line 61, in predict
    return self._automl.predict(X, batch_size=batch_size, n_jobs=n_jobs)
  File "/usr/local/lib/python3.6/site-packages/autosklearn/estimators.py", line 589, in predict
    X, batch_size=batch_size, n_jobs=n_jobs)
  File "/usr/local/lib/python3.6/site-packages/autosklearn/automl.py", line 545, in predict
    for identifier in self.ensemble_.get_model_identifiers())
  File "/usr/local/lib/python3.6/site-packages/sklearn/externals/joblib/parallel.py", line 758, in __call__
    while self.dispatch_one_batch(iterator):
  File "/usr/local/lib/python3.6/site-packages/sklearn/externals/joblib/parallel.py", line 608, in dispatch_one_batch
    self._dispatch(tasks)
  File "/usr/local/lib/python3.6/site-packages/sklearn/externals/joblib/parallel.py", line 571, in _dispatch
    job = self._backend.apply_async(batch, callback=cb)
  File "/usr/local/lib/python3.6/site-packages/sklearn/externals/joblib/_parallel_backends.py", line 109, in apply_async
    result = ImmediateResult(func)
  File "/usr/local/lib/python3.6/site-packages/sklearn/externals/joblib/_parallel_backends.py", line 326, in __init__
    self.results = batch()
  File "/usr/local/lib/python3.6/site-packages/sklearn/externals/joblib/parallel.py", line 131, in __call__
    return [func(*args, **kwargs) for func, args, kwargs in self.items]
  File "/usr/local/lib/python3.6/site-packages/sklearn/externals/joblib/parallel.py", line 131, in <listcomp>
    return [func(*args, **kwargs) for func, args, kwargs in self.items]
  File "/usr/local/lib/python3.6/site-packages/autosklearn/automl.py", line 45, in _model_predict
    prediction = model.predict_proba(X_, batch_size=batch_size)
  File "/usr/local/lib/python3.6/site-packages/autosklearn/pipeline/classification.py", line 131, in predict_proba
    raise Exception("batch_size must be a positive integer")
Exception: batch_size must be a positive integer
```




Discussion:
I am having the same issue, but I am not running a familiar database. My stack trace is:

```python
Exception                                 Traceback (most recent call last)
<ipython-input-12-f041cb16bc00> in <module>()
      1 cls = autosklearn.classification.AutoSklearnClassifier(include_preprocessors=["no_preprocessing"])
      2 cls.fit(X_train, y_train)
----> 3 predictions = cls.predict(X_test, y_test)

/usr/lib64/python3.5/site-packages/autosklearn/estimators.py in predict(self, X, batch_size, n_jobs)
    419         """
    420         return super(AutoSklearnClassifier, self).predict(
--> 421             X, batch_size=batch_size, n_jobs=n_jobs)
    422 
    423     def predict_proba(self, X, batch_size=None, n_jobs=1):

/usr/lib64/python3.5/site-packages/autosklearn/estimators.py in predict(self, X, batch_size, n_jobs)
     59 
     60     def predict(self, X, batch_size=None, n_jobs=1):
---> 61         return self._automl.predict(X, batch_size=batch_size, n_jobs=n_jobs)
     62 
     63     def score(self, X, y):

/usr/lib64/python3.5/site-packages/autosklearn/estimators.py in predict(self, X, batch_size, n_jobs)
    587     def predict(self, X, batch_size=None, n_jobs=1):
    588         predicted_probabilities = self._automl.predict(
--> 589             X, batch_size=batch_size, n_jobs=n_jobs)
    590 
    591         if self._n_outputs == 1:

/usr/lib64/python3.5/site-packages/autosklearn/automl.py in predict(self, X, batch_size, n_jobs)
    543         all_predictions = joblib.Parallel(n_jobs=n_jobs)(
    544             joblib.delayed(_model_predict)(self, X, batch_size, identifier)
--> 545             for identifier in self.ensemble_.get_model_identifiers())
    546 
    547         if len(all_predictions) == 0:

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/parallel.py in __call__(self, iterable)
    756             # was dispatched. In particular this covers the edge
    757             # case of Parallel used with an exhausted iterator.
--> 758             while self.dispatch_one_batch(iterator):
    759                 self._iterating = True
    760             else:

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/parallel.py in dispatch_one_batch(self, iterator)
    606                 return False
    607             else:
--> 608                 self._dispatch(tasks)
    609                 return True
    610 

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/parallel.py in _dispatch(self, batch)
    569         dispatch_timestamp = time.time()
    570         cb = BatchCompletionCallBack(dispatch_timestamp, len(batch), self)
--> 571         job = self._backend.apply_async(batch, callback=cb)
    572         self._jobs.append(job)
    573 

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/_parallel_backends.py in apply_async(self, func, callback)
    107     def apply_async(self, func, callback=None):
    108         """Schedule a func to be run"""
--> 109         result = ImmediateResult(func)
    110         if callback:
    111             callback(result)

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/_parallel_backends.py in __init__(self, batch)
    324         # Don't delay the application, to avoid keeping the input
    325         # arguments in memory
--> 326         self.results = batch()
    327 
    328     def get(self):

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/parallel.py in __call__(self)
    129 
    130     def __call__(self):
--> 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
    132 
    133     def __len__(self):

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/parallel.py in <listcomp>(.0)
    129 
    130     def __call__(self):
--> 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
    132 
    133     def __len__(self):

/usr/lib64/python3.5/site-packages/autosklearn/automl.py in _model_predict(self, X, batch_size, identifier)
     43             prediction = model.predict(X_, batch_size=batch_size)
     44         else:
---> 45             prediction = model.predict_proba(X_, batch_size=batch_size)
     46     if len(prediction.shape) < 1 or len(X_.shape) < 1 or \
     47             X_.shape[0] < 1 or prediction.shape[0] != X_.shape[0]:

/usr/lib64/python3.5/site-packages/autosklearn/pipeline/classification.py in predict_proba(self, X, batch_size)
    129         else:
    130             if type(batch_size) is not int or batch_size <= 0:
--> 131                 raise Exception("batch_size must be a positive integer")
    132 
    133             else:

Exception: batch_size must be a positive integer

```
Youre using 3.5?  It must not be a Python version issue, in that case.
@nickeleres 3.5
Why did you closed it? Did you solve the problem? 
Thank you very much for reporting this. @nickeleres did you solve the issue?

I also just tried to reproduce locally, but it doesn't happen when I run one of the examples. Does this issue occur randomly or reproducible?

Anyway, as the error message is not too helpful, I also pushed a better error message to the development branch. In case the issue isn't solved yet, using the development branch instead of the master branch will give a better error message which should help debugging this issue.
I did not resolve, but I was also not able to reproduce on other data sets.  I closed so I could look into it without crowding your issue board.
Is it reproducible on the dataset you have? If yes, could you please use the latest version of the development branch and post the (new) error message; or, if the dataset is public, provide a minimal script so I can try this, too.
I uninstalled the lib and installed using: `sudo pip3 install -U git+https://github.com/automl/auto-sklearn@development`.

My output changed:

```
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-223d23b891eb> in <module>()
----> 1 predictions = automl.predict(X_test, y_test)

/usr/lib64/python3.5/site-packages/autosklearn/estimators.py in predict(self, X, batch_size, n_jobs)
    419         """
    420         return super(AutoSklearnClassifier, self).predict(
--> 421             X, batch_size=batch_size, n_jobs=n_jobs)
    422 
    423     def predict_proba(self, X, batch_size=None, n_jobs=1):

/usr/lib64/python3.5/site-packages/autosklearn/estimators.py in predict(self, X, batch_size, n_jobs)
     59 
     60     def predict(self, X, batch_size=None, n_jobs=1):
---> 61         return self._automl.predict(X, batch_size=batch_size, n_jobs=n_jobs)
     62 
     63     def score(self, X, y):

/usr/lib64/python3.5/site-packages/autosklearn/estimators.py in predict(self, X, batch_size, n_jobs)
    587     def predict(self, X, batch_size=None, n_jobs=1):
    588         predicted_probabilities = self._automl.predict(
--> 589             X, batch_size=batch_size, n_jobs=n_jobs)
    590 
    591         if self._n_outputs == 1:

/usr/lib64/python3.5/site-packages/autosklearn/automl.py in predict(self, X, batch_size, n_jobs)
    543         all_predictions = joblib.Parallel(n_jobs=n_jobs)(
    544             joblib.delayed(_model_predict)(self, X, batch_size, identifier)
--> 545             for identifier in self.ensemble_.get_model_identifiers())
    546 
    547         if len(all_predictions) == 0:

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/parallel.py in __call__(self, iterable)
    756             # was dispatched. In particular this covers the edge
    757             # case of Parallel used with an exhausted iterator.
--> 758             while self.dispatch_one_batch(iterator):
    759                 self._iterating = True
    760             else:

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/parallel.py in dispatch_one_batch(self, iterator)
    606                 return False
    607             else:
--> 608                 self._dispatch(tasks)
    609                 return True
    610 

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/parallel.py in _dispatch(self, batch)
    569         dispatch_timestamp = time.time()
    570         cb = BatchCompletionCallBack(dispatch_timestamp, len(batch), self)
--> 571         job = self._backend.apply_async(batch, callback=cb)
    572         self._jobs.append(job)
    573 

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/_parallel_backends.py in apply_async(self, func, callback)
    107     def apply_async(self, func, callback=None):
    108         """Schedule a func to be run"""
--> 109         result = ImmediateResult(func)
    110         if callback:
    111             callback(result)

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/_parallel_backends.py in __init__(self, batch)
    324         # Don't delay the application, to avoid keeping the input
    325         # arguments in memory
--> 326         self.results = batch()
    327 
    328     def get(self):

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/parallel.py in __call__(self)
    129 
    130     def __call__(self):
--> 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
    132 
    133     def __len__(self):

/usr/lib64/python3.5/site-packages/sklearn/externals/joblib/parallel.py in <listcomp>(.0)
    129 
    130     def __call__(self):
--> 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
    132 
    133     def __len__(self):

/usr/lib64/python3.5/site-packages/autosklearn/automl.py in _model_predict(self, X, batch_size, identifier)
     43             prediction = model.predict(X_, batch_size=batch_size)
     44         else:
---> 45             prediction = model.predict_proba(X_, batch_size=batch_size)
     46     if len(prediction.shape) < 1 or len(X_.shape) < 1 or \
     47             X_.shape[0] < 1 or prediction.shape[0] != X_.shape[0]:

/usr/lib64/python3.5/site-packages/autosklearn/pipeline/classification.py in predict_proba(self, X, batch_size)
    130             if not isinstance(batch_size, int):
    131                 raise ValueError("Argument 'batch_size' must be of type int, "
--> 132                                  "but is '%s'" % type(batch_size))
    133             if batch_size <= 0:
    134                 raise ValueError("Argument 'batch_size' must be positive, "

ValueError: Argument 'batch_size' must be of type int, but is '<class 'pandas.core.series.Series'>'
```


Thanks a lot @bahbbc for testing this. The issue is that you do `automl.predict(X_test, y_test)` and the second argument is then used as the batch size. You need to call `automl.predict(X_test)` instead. Is this call somewhere in the docs?
The docs that says it is this way: http://automl.github.io/auto-sklearn/stable/

```python 
>>> import autosklearn.classification
>>> cls = autosklearn.classification.AutoSklearnClassifier()
>>> cls.fit(X_train, y_train)
>>> predictions = cls.predict(X_test, y_test)
```

Resolving patch:
diff --git a/example/example_metrics.py b/example/example_metrics.py
--- a/example/example_metrics.py
+++ b/example/example_metrics.py
@@ -49,7 +49,7 @@ def main():
 
     # Second example: Use own accuracy metric
     print("#"*80)
-    print("Use self defined accuracy accuracy metric")
+    print("Use self defined accuracy metric")
     accuracy_scorer = autosklearn.metrics.make_scorer(name="accu",
                                                       score_func=accuracy,
                                                       greater_is_better=True,


Test patch: