@@ -87,9 +87,20 @@ def _data_setter(self, X) -> None:
8787
8888 This method is used internally to register new data for the model for
8989 prediction.
90+
91+ NOTE: We are actively changing the `X`. Often, this matrix will have a different
92+ number of rows than the original data. So to make the shapes work, we need to
93+ update all data nodes in the model to have the correct shape. The values are not
94+ used, so we set them to 0. In our case, we just have data nodes X and y, but if
95+ in the future we get more complex models with more data nodes, then we'll need
96+ to update all of them - ideally programmatically.
9097 """
98+ new_no_of_observations = X .shape [0 ]
9199 with self :
92- pm .set_data ({"X" : X })
100+ pm .set_data (
101+ {"X" : X , "y" : np .zeros (new_no_of_observations )},
102+ coords = {"obs_ind" : np .arange (new_no_of_observations )},
103+ )
93104
94105 def fit (self , X , y , coords : Optional [Dict [str , Any ]] = None ) -> None :
95106 """Draw samples from posterior, prior predictive, and posterior predictive
@@ -111,7 +122,7 @@ def fit(self, X, y, coords: Optional[Dict[str, Any]] = None) -> None:
111122 )
112123 return self .idata
113124
114- def predict (self , X ):
125+ def predict (self , X : np . ndarray ):
115126 """
116127 Predict data given input data `X`
117128
@@ -206,7 +217,7 @@ class LinearRegression(PyMCModel):
206217 >>> lr = LinearRegression(sample_kwargs={"progressbar": False})
207218 >>> lr.fit(X, y, coords={
208219 ... 'coeffs': ['x', 'treated'],
209- ... 'obs_indx ': np.arange(rd.shape[0])
220+ ... 'obs_ind ': np.arange(rd.shape[0])
210221 ... },
211222 ... )
212223 Inference data...
@@ -451,7 +462,7 @@ class PropensityScore(PyMCModel):
451462 >>> ps = PropensityScore(sample_kwargs={"progressbar": False})
452463 >>> ps.fit(X, t, coords={
453464 ... 'coeffs': ['age', 'race'],
454- ... 'obs_indx ': np.arange(df.shape[0])
465+ ... 'obs_ind ': np.arange(df.shape[0])
455466 ... },
456467 ... )
457468 Inference...
0 commit comments