I’m trying to make a model in Pystan on my data. But, I keep receiving the initialization failed error. I have checked all the previous questions and the data format for me is changed to np.asarray
model_code_bel_copy = “”"
functions {
real sigmoid(real x, real g) {
return 1.0/(1.0 + exp(-g*x));
}
real sigmoid_simple(real x) {
return 1.0/(1.0 + exp(-x));
}
}
data {
int<lower=0> N;
int action[N];
int item[N];
}
parameters {
real<lower=0, upper=1> bel_prob[3];
}
transformed parameters {
real V[N];
real act[N];
for (i in 1:N) {
V[i] = bel_prob[item[i]];
act[i] = sigmoid_simple(V[i]);
}
}
model {
action ~ bernoulli(act);
}
“”"
Here is my 10 fold cross validation on it the model where I get the initialization error while fitting the data on the model
K fold cross validation
K = 10
kf = KFold(n_splits=K)
kf.get_n_splits(actions)
train_loglikelihood = []
train_loglikelihood_sum = []
test_loglikelihood = []
test_loglikelihood_sum = []
train_auc_score = []
test_auc_score = []
for train_index, test_index in kf.split(actionTmp):
actions_train, actions_test = actions[train_index], actions[test_index]
beliefs_train, beliefs_test = beliefs[train_index], beliefs[test_index]
items_train, items_test = items[train_index], items[test_index]
#trusts_train, trusts_test = trusts[train_index], trusts[test_index]
model_data_bel = {
'N' : len(actions_train),
'action': actions_train,
'item': items_train
}
fit = pystan.stan(model_code=model_code_bel_copy, data=model_data_bel,iter=2000, chains=4, n_jobs= 1)
In case there is a need for the error and
as well as how my data looks like
Any help on how I can fix it is greatly appreciated. Thanks