Skip to content
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

GaussianProcess with batch_size gives "'float' object cannot be interpreted as an integer" #6483

Closed
stmax82 opened this issue Mar 4, 2016 · 5 comments

Comments

@stmax82
Copy link

stmax82 commented Mar 4, 2016

Windows-10-10.0.10586
Python 3.4.4 |Continuum Analytics, Inc.| (default, Jan 29 2016, 15:20:20) [MSC v.1600 64 bit (AMD64)]
NumPy 1.10.4
SciPy 0.17.0
Scikit-Learn 0.17.1

The following code:

import numpy as np
from sklearn.gaussian_process import GaussianProcess

X = np.random.rand(100, 3)
y = np.random.rand(100)

gp = GaussianProcess().fit(X, y)

gp.predict(X, batch_size=5)

Results in the error

'float' object cannot be interpreted as an integer

Because of:

C:\...\lib\site-packages\sklearn\gaussian_process\gaussian_process.py in predict(self, X, eval_MSE, batch_size)
    520 
    521                 y = np.zeros(n_eval)
--> 522                 for k in range(max(1, n_eval / batch_size)):
    523                     batch_from = k * batch_size
    524                     batch_to = min([(k + 1) * batch_size + 1, n_eval + 1])

TypeError: 'float' object cannot be interpreted as an integer
@glouppe
Copy link
Contributor

glouppe commented Mar 4, 2016

GaussianProcess has been deprecated in 0.18. If this is possible for you, please update to the dev version, where will now find GaussianProcessRegressor instead.

@glouppe glouppe closed this as completed Mar 4, 2016
@stmax82
Copy link
Author

stmax82 commented Mar 4, 2016

oh thanks, I didn't know the GaussianProcess class was deprecated (there's no warning anywhere). Wish I could try the new one in 0.18, but I cannot use dev versions in production.

Will there be a 0.17.2 release before 0.18? The fix would be trivial - I think replacing the division "/" by "//" should do it..

@nelson-liu
Copy link
Contributor

@glouppe according to the docstring at https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/gaussian_process/gaussian_process.py#L61, it will be deprecated in 0.20. Is this an error in the docstring?

@glouppe
Copy link
Contributor

glouppe commented Mar 4, 2016

No, this is correct. The new GP implementation has been added after the 0.17 release, and therefore the old implementation will be deprecated in 0.20, two release cycles after the next 0.18 release.

GaussianProcess is deprecated starting from 0.18 but it is still there until 0.20, where it will be entirely removied.

@nelson-liu
Copy link
Contributor

ah that makes sense, thanks for the info.

ccphillippi added a commit to ccphillippi/scikit-learn that referenced this issue Sep 4, 2016
Fixes scikit-learn#7329 and scikit-learn#6483

I realize this is deprecated, but in case you're still interested in a quick bugfix, my understanding is that this was previously a silent bug even in Python 2.7.

```
import numpy as np

def check_mse(n_eval, batch_size):

    y, MSE = np.zeros(n_eval), np.zeros(n_eval)
    for k in range(max(1, n_eval / batch_size)):
        batch_from = k * batch_size
        batch_to = min([(k + 1) * batch_size + 1, n_eval + 1])
    
        print batch_from, batch_to

def check_mse_fixed(n_eval, batch_size):

    y, MSE = np.zeros(n_eval), np.zeros(n_eval)
    for k in range(int(n_eval / float(batch_size) + 0.5)):
        batch_from = k * batch_size
        batch_to = min([(k + 1) * batch_size + 1, n_eval + 1])
    
        print batch_from, batch_to
        
        
check_mse(8, 3)
print
check_mse_fixed(8, 3)
```
Python 2.7 output:
```
0 4
3 7

0 4
3 7
6 9
```
Note 8 corresponds to the sample size so the current version (if converted to an int) would miss the last few samples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants