@@ -54,18 +54,18 @@ class PyMCModel(pm.Model):
54
54
... "chains": 2,
55
55
... "draws": 2000,
56
56
... "progressbar": False,
57
- ... "random_seed": rng ,
57
+ ... "random_seed": 42 ,
58
58
... }
59
59
... )
60
60
>>> model.fit(X, y)
61
61
Inference data...
62
+ >>> model.score(X, y) # doctest: +ELLIPSIS
63
+ r2 ...
64
+ r2_std ...
65
+ dtype: float64
62
66
>>> X_new = rng.normal(loc=0, scale=1, size=(20,2))
63
67
>>> model.predict(X_new)
64
68
Inference data...
65
- >>> model.score(X, y)
66
- r2 0.390344
67
- r2_std 0.081135
68
- dtype: float64
69
69
"""
70
70
71
71
def __init__ (self , sample_kwargs : Optional [Dict [str , Any ]] = None ):
@@ -123,7 +123,6 @@ def predict(self, X):
123
123
# Ensure random_seed is used in sample_prior_predictive() and
124
124
# sample_posterior_predictive() if provided in sample_kwargs.
125
125
random_seed = self .sample_kwargs .get ("random_seed" , None )
126
-
127
126
self ._data_setter (X )
128
127
with self : # sample with new input data
129
128
post_pred = pm .sample_posterior_predictive (
@@ -137,18 +136,19 @@ def predict(self, X):
137
136
def score (self , X , y ) -> pd .Series :
138
137
"""Score the Bayesian :math:`R^2` given inputs ``X`` and outputs ``y``.
139
138
139
+ Note that the score is based on a comparison of the observed data ``y`` and the
140
+ model's expected value of the data, `mu`.
141
+
140
142
.. caution::
141
143
142
144
The Bayesian :math:`R^2` is not the same as the traditional coefficient of
143
145
determination, https://en.wikipedia.org/wiki/Coefficient_of_determination.
144
146
145
147
"""
146
- yhat = self .predict (X )
147
- yhat = az .extract (
148
- yhat , group = "posterior_predictive" , var_names = "y_hat"
149
- ).T .values
148
+ mu = self .predict (X )
149
+ mu = az .extract (mu , group = "posterior_predictive" , var_names = "mu" ).T .values
150
150
# Note: First argument must be a 1D array
151
- return r2_score (y .flatten (), yhat )
151
+ return r2_score (y .flatten (), mu )
152
152
153
153
def calculate_impact (self , y_true , y_pred ):
154
154
pre_data = xr .DataArray (y_true , dims = ["obs_ind" ])
0 commit comments