You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Prediction cannot proceed on a pandas dataframe, since the BCF model was not fit with a covariate preprocessor. Please refit your model by passing covariate data as a Pandas dataframe."
2282
-
)
2283
-
else:
2284
-
warnings.warn(
2285
-
"This BCF model has not run any covariate preprocessing routines. We will attempt to predict on the raw covariate values, but this will trigger an error with non-numeric columns. Please refit your model by passing non-numeric covariate data a a Pandas dataframe.",
"Prediction cannot proceed on a non-numeric numpy array, since the BCF model was not fit with a covariate preprocessor. Please refit your model by passing non-numeric covariate data as a Pandas dataframe."
"""Predict expected conditional variance from a BART model.
2346
-
2347
-
Parameters
2348
-
----------
2349
-
covariates : np.array
2350
-
Test set covariates.
2351
-
propensity : np.array, optional
2352
-
Test set propensity scores. Optional (not currently used in variance forests).
2353
-
2354
-
Returns
2355
-
-------
2356
-
np.array
2357
-
Array of predictions corresponding to the variance forest. Each array will contain as many rows as in `covariates` and as many columns as retained samples of the algorithm.
2358
-
"""
2359
-
ifnotself.is_sampled():
2360
-
msg= (
2361
-
"This BARTModel instance is not fitted yet. Call 'fit' with "
2362
-
"appropriate arguments before using this model."
2363
-
)
2364
-
raiseNotSampledError(msg)
2365
-
2366
-
ifnotself.include_variance_forest:
2367
-
msg= (
2368
-
"This BARTModel instance was not sampled with a variance forest. "
2369
-
"Call 'fit' with appropriate arguments before using this model."
2370
-
)
2371
-
raiseNotSampledError(msg)
2372
-
2373
-
# Convert everything to standard shape (2-dimensional)
"Prediction cannot proceed on a pandas dataframe, since the BCF model was not fit with a covariate preprocessor. Please refit your model by passing covariate data as a Pandas dataframe."
2385
-
)
2386
-
else:
2387
-
warnings.warn(
2388
-
"This BCF model has not run any covariate preprocessing routines. We will attempt to predict on the raw covariate values, but this will trigger an error with non-numeric columns. Please refit your model by passing non-numeric covariate data a a Pandas dataframe.",
"Prediction cannot proceed on a non-numeric numpy array, since the BCF model was not fit with a covariate preprocessor. Please refit your model by passing non-numeric covariate data as a Pandas dataframe."
"""Predict outcome model components (CATE function and prognostic function) as well as overall outcome for every provided observation.
2462
2247
Predicted outcomes are computed as `yhat = mu_x + Z*tau_x` where mu_x is a sample of the prognostic function and tau_x is a sample of the treatment effect (CATE) function.
@@ -2473,16 +2258,29 @@ def predict(
2473
2258
Optional group labels used for an additive random effects model.
2474
2259
rfx_basis : np.array, optional
2475
2260
Optional basis for "random-slope" regression in an additive random effects model.
2476
-
2477
2261
type : str, optional
2478
2262
Type of prediction to return. Options are "mean", which averages the predictions from every draw of a BART model, and "posterior", which returns the entire matrix of posterior predictions. Default: "posterior".
2479
2263
terms : str, optional
2480
2264
Which model terms to include in the prediction. This can be a single term or a list of model terms. Options include "y_hat", "prognostic_function", "cate", "rfx", "variance_forest", or "all". If a model doesn't have mean forest, random effects, or variance forest predictions, but one of those terms is request, the request will simply be ignored. If none of the requested terms are present in a model, this function will return `NULL` along with a warning. Default: "all".
2265
+
scale : str, optional
2266
+
Scale on which to return predictions. Options are "linear" (the default), which returns predictions on the original outcome scale, and "probit", which returns predictions on the probit (latent) scale. Only applicable for models fit with `probit_outcome_model=True`.
2481
2267
2482
2268
Returns
2483
2269
-------
2484
2270
Dict of numpy arrays for each prediction term, or a simple numpy array if a single term is requested.
2485
2271
"""
2272
+
# Handle mean function scale
2273
+
ifnotisinstance(scale, str):
2274
+
raiseValueError("scale must be a string")
2275
+
ifscalenotin ["linear", "probability"]:
2276
+
raiseValueError("scale must either be 'linear' or 'probability'")
2277
+
is_probit=self.probit_outcome_model
2278
+
if (scale=="probability") and (notis_probit):
2279
+
raiseValueError(
2280
+
"scale cannot be 'probability' for models not fit with a probit outcome model"
0 commit comments