2
$\begingroup$

I'm using statsmodels.nonparametric.KDEMultivariate to generate continuous probability distributions with kernel density estimation. The distribution is created using statsmodels.nonparametric.KDEMultivariate(data=[time, measurement]) to create a distribution, and then if I want to find a discretised most likely measurement from my distribution for a particular time, I can iterate through with:

for x in range(10):
    probability_of_x = distribution.pdf([TIME, x])

Where TIME is the fixed time value for which I want to obtain a "best prediction".

What I'm struggling with is how to work out the expected value from a distribution like this, as I know that iterating through as I am to find the "best prediction" is the wrong way to go about it.

Is there a python library or something similar that I could use to get the expected value for a fixed time?

Many thanks in advance.

$\endgroup$
0

1 Answer 1

4
$\begingroup$

I'm not quite familiar with statsmodels, but if you have data values, $x_1, \ldots, x_n$, and probabilities of these values $p_1, \ldots, p_n$ given to you by the function distribution.pdf(), then an estimator for the expected value could be $$ \widehat{E[X]} = \sum_{i=1}^n p_i x_i, $$ which might be something like this

ave = 0
time = 0
for datum in data:
    ave += datum * distribution.pdf([time, x])
    time += 1
print ave

Maybe not though. Like @michaelchernick says, this forum isn't really for programming help.

$\endgroup$
3
  • $\begingroup$ Thanks for your reply - I was originally going to use a method like this, but surely discretising a continuous distribution and then working out the expected value from this will result in a value that's too small? With regards to the comments about programming help, it seems like my question is better suited to StackOverflow. :) $\endgroup$
    – helencrump
    Commented Apr 1, 2017 at 22:11
  • 1
    $\begingroup$ @helencrump all data is discrete, so I wouldn't worry about that. I don't see why it would be too small, though. I don't have much experience with nonparametric density estimation, so I am embarassed to say that I do not know how people use the density curve to do anything. With parametric estimation, you get parameter estimates $\hat{\theta}$, and then just plug them into the function of interest usually. $\endgroup$
    – Taylor
    Commented Apr 1, 2017 at 22:19
  • 2
    $\begingroup$ Marking this as the answer as I realised that I hadn't normalised any of my probabilities, which is why my results were always so small when using this method. Thanks so much for the help! $\endgroup$
    – helencrump
    Commented Apr 1, 2017 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.