Skip to content

Commit

Permalink
Added test of y_training shape so that if it is given as a 2d array a…
Browse files Browse the repository at this point in the history
…nd incorrectly transposed it will be fixed, also the return values will be given in the same form as the training values
  • Loading branch information
JohnFNovak committed Apr 2, 2013
1 parent be2984a commit 0a1e6f7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sklearn/gaussian_process/gaussian_process.py
Expand Up @@ -274,8 +274,12 @@ def fit(self, X, y):
self.y_shape = np.array(y).shape
y = array2d(y)

# If the y values are given to fit() as a list:
if len(self.y_shape) == 1:
y = y.T
# If the y vales are given to fit() as an array, but transposed wrong
elif self.y_shape[0] == 1 and self.y_shape[1] == X.shape[0]:
y = y.T

# Check shapes of DOE & observations
n_samples_X, n_features = X.shape
Expand Down Expand Up @@ -461,6 +465,8 @@ def predict(self, X, eval_MSE=False, batch_size=None):

if len(self.y_shape) == 1:
y = y.ravel()
elif self.y_shape[0] == 1 and self.y_shape[1] == X.shape[0]:
y = y.T

# Mean Squared Error
if eval_MSE:
Expand Down Expand Up @@ -496,6 +502,8 @@ def predict(self, X, eval_MSE=False, batch_size=None):

if len(self.y_shape) == 1:
MSE = MSE.ravel()
elif self.y_shape[0] == 1 and self.y_shape[1] == X.shape[0]:
MSE = MSE.T

return y, MSE

Expand Down

0 comments on commit 0a1e6f7

Please sign in to comment.