0

Say I have a dataframe as below.

company model   rating  type    year
ford    mustang A   coupe   2018
chevy   camaro  B   coupe   2018
ford    fiesta  C   sedan   2021
ford    focus   A   sedan   2022
ford    taurus  B   sedan   2021
toyota  camry   B   sedan   2018

I want to calculate conditional probabilities but dynamically, based on the selections made in PowerBI. The final conditional probability needs to be displayed in PowerBI.

I am trying to calculate the conditional probabilities in Python.

So I want to calculate the probability of 'ratings' column conditional on the selections made on powerBI.

So if user selects, year = 2018, then

P(rating = A | year = 2018)
P(rating = B | year = 2018)
P(rating = C | year = 2018)

In another case if user selects, year = 2018 and company = Toyota

P(rating = A | year = 2018, company = Toyota)
P(rating = B | year = 2018, company = Toyota)
P(rating = C | year = 2018, company = Toyota)
  1. I am trying to get the user selection made in powerBI as a variable and create a process to use it as a variable in python script. Then based on these variables calculate the conditional probability and display it in powerBI. Is it possible to export the user selections made in powerBI into a variable in powerBI? From powerBI, I can create a measure using SELECTEDVALUE to capture the selections made in PowerBI, but how can this be linked into python.

  2. To calculate the conditional probability between two events I have used the approach in here.

    rating_probs = df.groupby('rating').size().div(len(df))

    df.groupby(['type', 'rating']).size().div(len(df)).div(rating_probs, axis=0, level='rating')

How can this be extended to calculate the conditional probability of several events? (e.g. P(rating = C | year = 2018, company = Toyota)

sam_rox
  • 739
  • 3
  • 14
  • 29

0 Answers0