I’m trying to follow Chapter 2 of Model Based Machine Learning http://mbmlbook.com/LearningSkills_Moving_to_real_data.html
It’s about assessing people’s skills through questions they answer. The generative model is such that there are 7 skills and 48 questions. Each question may test one or more skills. I initialize each skill as a Bernoulli (shape of 7, since there are 7 skills)
skills = pm.Bernoulli(‘skills’, p=0.5*np.ones(len(df_skills.columns)), shape=len(df_skills.columns))
Next, I want to loop through each question, checking which all skills are required to answer that question. I do that through
hasAllSkillsForQuestionP = np.ones(len(df_correct.columns)) for q in range(len(df_correct.columns)): skills_indexes_needed_for_this_q = np.where(df_skills_per_q.transpose()[q].tolist()) for skill in skills_indexes_needed_for_this_q: hasAllSkillsForQuestionP[q] = hasAllSkillsForQuestionP[q]*skills[skill]
And then I add unpredictability (that is, if a candidate has all skills for answering a question, probability of correct=0.9, if the candidate doesn’t have all skills, probability of correct = guessing = 0.2… it’s MCQ of 5 questions)
isCorrectQuestion = pm.Deterministic('isCorrectQuestion', pm.math.switch(hasAllSkillsForQuestionP, pm.Bernoulli(p=0.9), pm.Bernoulli(p=0.2)))
When I try compiling the code, I get this error:
ValueError Traceback (most recent call last)
15 for skill in skills_indexes_needed_for_this_q:
—> 17 hasAllSkillsForQuestionP[q] = hasAllSkillsForQuestionP[q]*skills[skill]
19 #hasAllSkillsForQuestion = pm.Bernoulli(‘hasAllSkillsForQuestion’, p=hasAllSkillsForQuestionP, shape=len(hasAllSkillsForQuestionP))
ValueError: setting an array element with a sequence.
Why is this happening? As per docs, random variables with shape support full indexing like
y = x * x # full indexing is supported
How do I fix this?