@@ -1285,25 +1285,25 @@ def score(self, X, y=None, sample_weight=None, output_weight=None,
1285
1285
1286
1286
# def score_samples(self, X, y, missing=None):
1287
1287
# '''
1288
- #
1288
+ #
1289
1289
# Calculate sample-wise fit scores.
1290
- #
1290
+ #
1291
1291
# Parameters
1292
1292
# ----------
1293
- #
1293
+ #
1294
1294
# X : array-like, shape = [m, n] where m is the number of samples
1295
1295
# and n is the number of features The training predictors.
1296
1296
# The X parameter can be a numpy array, a pandas DataFrame, a patsy
1297
1297
# DesignMatrix, or a tuple of patsy DesignMatrix objects as output
1298
1298
# by patsy.dmatrices.
1299
- #
1299
+ #
1300
1300
# y : array-like, optional (default=None), shape = [m, p] where m is the
1301
1301
# number of samples, p the number of outputs.
1302
1302
# The y parameter can be a numpy array, a pandas DataFrame,
1303
1303
# a Patsy DesignMatrix, or can be left as None (default) if X was
1304
1304
# the output of a call to patsy.dmatrices (in which case, X contains
1305
1305
# the response).
1306
- #
1306
+ #
1307
1307
# missing : array-like, shape = [m, n] where m is the number of samples
1308
1308
# and n is the number of features.
1309
1309
# The missing parameter can be a numpy array, a pandas DataFrame, or
@@ -1312,22 +1312,29 @@ def score(self, X, y=None, sample_weight=None, output_weight=None,
1312
1312
# interpreted as missing. If the missing argument not used but the X
1313
1313
# argument is a pandas DataFrame, missing will be inferred from X if
1314
1314
# allow_missing is True.
1315
- #
1315
+ #
1316
1316
# Returns
1317
1317
# -------
1318
- #
1318
+ #
1319
1319
# scores : array of shape=[m, p] of floats with maximum value of 1
1320
1320
# (it can be negative).
1321
1321
# The scores represent how good each output of each example is
1322
1322
# predicted, a perfect score would be 1
1323
1323
# (the score can be negative).
1324
- #
1324
+ #
1325
1325
# '''
1326
1326
# X, y, sample_weight, output_weight, missing = self._scrub(
1327
1327
# X, y, None, None, missing)
1328
1328
# y_hat = self.predict(X, missing=missing)
1329
- # residual = 1 - (y - y_hat) ** 2 / y**2
1330
- # return residual
1329
+ # if y_hat.ndim == 1:
1330
+ # y_hat = y_hat.reshape(-1, 1)
1331
+ # squared_errors = (y - y_hat) ** 2
1332
+ # variances = np.var(y, axis=0).reshape(1, -1)
1333
+ # nze = variances != 0 # non-zero variance
1334
+ # nze = nze.ravel()
1335
+ # output = np.ones(squared_errors.shape)
1336
+ # output[:, nze] = 1 - squared_errors[:, nze] / variances[:, nze]
1337
+ # return output
1331
1338
1332
1339
def transform (self , X , missing = None ):
1333
1340
'''
0 commit comments