Hello and thank you to all the developers for your continued support.
I want to predict new data with a model using BART.
So I used the method pm.MutableData() and pass the value to BART like this…
data_X = pm.MutableData("df_X", df_X[use_cols])
data_y = pm.MutableData("df_y", df_y[target_cols[0]])
σ = pm.Normal("σ", model_params["Normal"]["σ"])
μ = pmb.BART("μ", data_X, data_y, m=model_params["BART"]["m"], alpha=model_params["BART"]["alpha"])
y = pm.Normal("y", μ, σ, observed=data_y)
I got an error.
TypeError Traceback (most recent call last)
<ipython-input-106-135349d654bb> in <module>
34 # μ = pmb.BART("μ", df_X[use_cols], df_y[target_cols[0]], m=model_params["BART"]["m"], alpha=model_params["BART"]["alpha"]) #パラメタの事前分布
35 # y = pm.Normal("y", μ, σ, observed=df_y[target_cols[0]]) #尤度関数
---> 36 μ = pmb.BART("μ", data_X, data_y, m=model_params["BART"]["m"], alpha=model_params["BART"]["alpha"]) #パラメタの事前分布
37 y = pm.Normal("y", μ, σ, observed=data_y) #尤度関数
38
1 frames
/usr/local/lib/python3.7/dist-packages/numpy/core/numeric.py in ones(shape, dtype, order, like)
202 return _ones_with_like(shape, dtype=dtype, order=order, like=like)
203
--> 204 a = empty(shape, dtype, order)
205 multiarray.copyto(a, 1, casting='unsafe')
206 return a
TypeError: expected sequence object with len >= 0 or a single integer
It worked fine when I just passed a pandas DataFrame directly.
And I know there is a function for predicting new data on BART.
# it works.
predict = pmb.predict(trace, rng, df_X[use_cols].values, 100)
but I think I should use the “sample_posterior_predivtive” function for predicting new data by whole posterior distribution(take the average for prediction) like below.
with bart_model:
pm.set_data({"df_X": test_X})
posterior_predictive = pm.sample_posterior_predictive(trace)
But pm.MutableData function didn’t work.
So, how to predict new data with a model using BART?
Is using the BART’s predict function a correct way?
Thanks.