Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit 2b609ed

Browse files
committed
Merge with PR #184
2 parents c11bb38 + 15faf82 commit 2b609ed

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

pyearth/earth.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,25 +1285,25 @@ def score(self, X, y=None, sample_weight=None, output_weight=None,
12851285

12861286
# def score_samples(self, X, y, missing=None):
12871287
# '''
1288-
#
1288+
#
12891289
# Calculate sample-wise fit scores.
1290-
#
1290+
#
12911291
# Parameters
12921292
# ----------
1293-
#
1293+
#
12941294
# X : array-like, shape = [m, n] where m is the number of samples
12951295
# and n is the number of features The training predictors.
12961296
# The X parameter can be a numpy array, a pandas DataFrame, a patsy
12971297
# DesignMatrix, or a tuple of patsy DesignMatrix objects as output
12981298
# by patsy.dmatrices.
1299-
#
1299+
#
13001300
# y : array-like, optional (default=None), shape = [m, p] where m is the
13011301
# number of samples, p the number of outputs.
13021302
# The y parameter can be a numpy array, a pandas DataFrame,
13031303
# a Patsy DesignMatrix, or can be left as None (default) if X was
13041304
# the output of a call to patsy.dmatrices (in which case, X contains
13051305
# the response).
1306-
#
1306+
#
13071307
# missing : array-like, shape = [m, n] where m is the number of samples
13081308
# and n is the number of features.
13091309
# 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,
13121312
# interpreted as missing. If the missing argument not used but the X
13131313
# argument is a pandas DataFrame, missing will be inferred from X if
13141314
# allow_missing is True.
1315-
#
1315+
#
13161316
# Returns
13171317
# -------
1318-
#
1318+
#
13191319
# scores : array of shape=[m, p] of floats with maximum value of 1
13201320
# (it can be negative).
13211321
# The scores represent how good each output of each example is
13221322
# predicted, a perfect score would be 1
13231323
# (the score can be negative).
1324-
#
1324+
#
13251325
# '''
13261326
# X, y, sample_weight, output_weight, missing = self._scrub(
13271327
# X, y, None, None, missing)
13281328
# 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
13311338

13321339
def transform(self, X, missing=None):
13331340
'''

0 commit comments

Comments
 (0)