Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GaussianProcess batch predict fail on py3 #7329

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

Closed
zhengruifeng opened this issue Sep 2, 2016 · 3 comments · Fixed by #7330 · May be fixed by ccphillippi/scikit-learn#1
Closed

GaussianProcess batch predict fail on py3 #7329

zhengruifeng opened this issue Sep 2, 2016 · 3 comments · Fixed by #7330 · May be fixed by ccphillippi/scikit-learn#1

Comments

@zhengruifeng
Copy link
Contributor

zhengruifeng commented Sep 2, 2016

Description

GaussianProcess batch predict fail on py3 due to range(float)

Steps/Code to Reproduce

import numpy as np
import sklearn.datasets
from sklearn import gaussian_process

digits = sklearn.datasets.load_digits()

X = digits.data
y = digits.target

indices = np.arange(X.shape[0])
np.random.shuffle(indices)
X = X[indices]
y = y[indices]
X_train = X[:1000]
y_train = y[:1000]
X_test = X[1000:]
y_test = y[1000:]

gp = gaussian_process.GaussianProcess()
gp.fit(X_train, y_train)

gp.predict(X_test, batch_size=100)

Expected Results

No error is thrown.

Actual Results

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-b96b929502ec> in <module>()
----> 1 gp.predict(X_test, batch_size=100)

/usr/local/lib/python3.5/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

Versions

scikit-learn (0.17.1)
Python 3.5.2

@nelson-liu
Copy link
Contributor

Duplicate of #6483
GaussianProcess will be deprecated in the next release (0.18). If possible, run the code on latest master and use GaussianProcessRegressor .

@zhengruifeng
Copy link
Contributor Author

@nelson-liu Thanks. I will close this issue and pr.

@zhengruifeng
Copy link
Contributor Author

@nelson-liu Although it will be deprecated in (0.18), I think this PR may be useful before removal of GaussianProcess. So I reopen this PR.

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.
jnothman pushed a commit that referenced this issue Oct 6, 2016
amueller pushed a commit to amueller/scikit-learn that referenced this issue Oct 14, 2016
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this issue Jun 14, 2017
paulha pushed a commit to paulha/scikit-learn that referenced this issue Aug 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants