Fitting Probability Distributions to Data with SciPy (Python)

  Рет қаралды 14,872

Mike Saint-Antoine

Mike Saint-Antoine

2 жыл бұрын

UPDATE: I realized the method I used in this video, called fit() is only included for CONTINUOUS distributions (normal, gamma, exponential, etc) in SciPy. If you're trying to fit a DISCRETE distribution (Poisson, geometric, binomial, etc), I made a new video explaining how to do that:
• Fitting Discrete Distr...
UPDATE 2: After I made this video, SciPy 1.9 was released, which includes a new method that makes it easy to fit distributions to data, and can be used for both continuous and discrete distributions. Here is the link to the documentation for this method:
scipy.github.io/devdocs/refer...
Hi everyone! This video is about how to use the Python SciPy library to fit a probably distribution to data, using the normal distribution and gamma distribution as examples.
All the code from my videos is available on my Github:
github.com/mikesaint-antoine/...
Let me know if you have any questions! Thanks for watching!

Пікірлер: 26
@MikeSaintAntoine
@MikeSaintAntoine Жыл бұрын
Hi everyone, thanks for watching! Here's the link to the code on my Github in case you want to try it for yourself (also feel free to add me as a friend on Github if you want 🙂) : github.com/mikesaint-antoine/Comp_Bio_Tutorials/tree/main/parameter_estimation/continuous_distributions
@mohammadjavadbeirami9462
@mohammadjavadbeirami9462 Жыл бұрын
Very valuable explanation. Thank you
@MikeSaintAntoine
@MikeSaintAntoine Жыл бұрын
Thanks for watching Mohammad!
@andrewcameron5495
@andrewcameron5495 11 ай бұрын
Thank you very much for your helpful video! It was exactly what I was looking for. I just subscribed to your channel. Wishing you the best!
@MikeSaintAntoine
@MikeSaintAntoine 11 ай бұрын
Thanks Andrew! 🙂
@RobertLugg
@RobertLugg 2 жыл бұрын
Excellent video.
@MikeSaintAntoine
@MikeSaintAntoine 2 жыл бұрын
Thanks Robert! Let me know if you have any questions 🙂
@digantchavda9396
@digantchavda9396 Жыл бұрын
Thank you so much! Very helpful video!!
@MikeSaintAntoine
@MikeSaintAntoine Жыл бұрын
Thanks for watching Digant, and let me know if you have any questions! 🙂
@jameskaihatu6209
@jameskaihatu6209 Жыл бұрын
Python newbie here, emerging into the modern world from Fortran...77. I learned a lot. Thanks.
@MikeSaintAntoine
@MikeSaintAntoine Жыл бұрын
Thanks for watching James, and let me know if you have any questions! 🙂
@livialopes5682
@livialopes5682 2 ай бұрын
very helpful! Thanks :)
@MikeSaintAntoine
@MikeSaintAntoine Ай бұрын
Thanks for watching! 🙂
@ademikunle
@ademikunle Жыл бұрын
great tut!
@MikeSaintAntoine
@MikeSaintAntoine Жыл бұрын
Thanks for watching Adebisi!
@learning_with_irving4266
@learning_with_irving4266 7 ай бұрын
Dude, How are you so smart? Is it because your name is Michael and also a saint?
@MikeSaintAntoine
@MikeSaintAntoine 7 ай бұрын
Thanks lol
@nnamdiodozi7713
@nnamdiodozi7713 2 жыл бұрын
Great video Mike. What method do I use to fit to discrete distributions. I looked under the scipy binom object and there is no fit method. Is it possible to compute measure of fit eg least squares, AIC or BIC?
@MikeSaintAntoine
@MikeSaintAntoine 2 жыл бұрын
Hi Nnamdi, hmmmm that's a good question. I didn't realize this until now, but you're right, when I looked up some discrete distributions they don't have the fit() method, and I couldn't find any built-in method to do it in scipy. I'm not sure why that is. It can definitely still be done from scratch, but that is a bit more difficult. I think the way to do it is to just use the binomial probability mass function and then just treat it like you're fitting parameters to a regular function, varying the binomial distribution parameters. For example this is my video on fitting parameters to a logistic growth model: kzbin.info/www/bejne/fYeWmXSLhJVloc0 I would recommend trying to do this, except instead of the logistic growth model just use the binomial probability mass function. I'll try to make a video on this when I have more free time (I'm a bit busy with research and grad school at the moment). Thanks for watching!
@MikeSaintAntoine
@MikeSaintAntoine 2 жыл бұрын
Hi again Nnamdi! Ok I made a new video explaining how to do the parameter estimation for discrete distributions: kzbin.info/www/bejne/iqjFe3aqaJuSerc Hope this helps! I used the Poisson distribution here, but I think the same method will work for any discrete distribution that's included in the scipy.stats library. Let me know if you have any questions!
@nnamdiodozi7713
@nnamdiodozi7713 Жыл бұрын
@@MikeSaintAntoine Been trying to use scipy to fit a multivariate t distribution to stock returns. It can be done with a line in Matlab but scipy doesnt have any methods for the multivariate_t object to do this. Any ideas?
@MikeSaintAntoine
@MikeSaintAntoine Жыл бұрын
@@nnamdiodozi7713 Hi Nnamdi, good question. Yes I saw that SciPy's new scipy.stats.fit() function doesn't work for the multivariate_t distribution yet, even though SciPy has a multivariate_t distribution object: docs.scipy.org/doc/scipy/reference/generated/scipy.stats.multivariate_t.html So my advice here would be to attempt to do the fitting from scratch -- by defining a loss function and then minimizing it to find the parameters that fit the best. This is basically what I tried to do in my previous video on fitting discrete distributions (although with the new version of SciPy many discrete distributions can be fit with scipy.stats.fit()). That video is here: kzbin.info/www/bejne/iqjFe3aqaJuSerc Good luck, and thanks for watching my videos!
@pastorsoto1298
@pastorsoto1298 2 жыл бұрын
Great video! If you want to test U-shape distribution what test would you choose. I look at the documentation but couldn't find how to do it
@MikeSaintAntoine
@MikeSaintAntoine 2 жыл бұрын
Hi! That's a great question. I previously thought that all the scipy distributions had this fit() method to make the fitting easy, but apparently some of them don't have it (as another commenter pointed out). So for those, unfortunately I don't really have a good recommendation for how to easily do the fitting. It's still possible to do the fitting from scratch though. For that I would recommend checking out my video on fitting to the logistic growth model: kzbin.info/www/bejne/fYeWmXSLhJVloc0 And then just try to follow those steps, except instead of using the logistic growth function, just use the probability mass function for whichever distribution you're trying to fit to. Maybe I will also try to make a video on how to do the distribution fits from scratch in the future, if I have more time. Thanks for watching and good luck!
@MikeSaintAntoine
@MikeSaintAntoine 2 жыл бұрын
Hi again! I'm not sure which specific distribution you're talking about with the U-shape, but I made another video explaining how to fit discrete distributions in SciPy, which don't have the convenient fit() method. This can still be done by using their logpmf() function. Here is the video: kzbin.info/www/bejne/iqjFe3aqaJuSerc I used the Poisson distribution for an example, but I think this method should work for any discrete distribution included in SciPy. Hope that helps! Let me know if you have any questions!
@pastorsoto1298
@pastorsoto1298 2 жыл бұрын
@@MikeSaintAntoine Amazing. Thank you!!
Fitting the Predator-Prey Model to Data (Python)
28:26
Mike Saint-Antoine
Рет қаралды 2,8 М.
Fitting Probability Distributions to Data with SciPy (UPDATED VERSION)
21:53
Mike Saint-Antoine
Рет қаралды 4,3 М.
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 127 МЛН
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 170 #shorts
00:27
Vivaan  Tanya once again pranked Papa 🤣😇🤣
00:10
seema lamba
Рет қаралды 29 МЛН
FOOLED THE GUARD🤢
00:54
INO
Рет қаралды 63 МЛН
Python for Data Analysis: Probability Distributions
32:47
DataDaft
Рет қаралды 55 М.
The Beta distribution in 12 minutes!
13:31
Serrano.Academy
Рет қаралды 79 М.
5 Probability Distributions you should know as a Data Scientist
14:57
Unlock the Secret of Nonlinear Curve Fitting - Python LMFIT
18:18
The Normal Distribution, Clearly Explained!!!
5:13
StatQuest with Josh Starmer
Рет қаралды 1,3 МЛН
How to: Import, Plot, Fit, and Integrate Data in Python
24:11
Curve Fitting in Python (2022)
24:50
Mr. P Solver
Рет қаралды 89 М.
Probability: Types of Distributions
7:24
365 Data Science
Рет қаралды 356 М.
Intro to Scipy Optimization: Minimize Method
26:26
TokyoEdtech
Рет қаралды 36 М.
Fitting Raman Data using Python
14:21
Dr Manab
Рет қаралды 4,6 М.
cute mini iphone
0:34
승비니 Seungbini
Рет қаралды 6 МЛН
Урна с айфонами!
0:30
По ту сторону Гугла
Рет қаралды 8 МЛН
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 3,4 МЛН
YOTAPHONE 2 - СПУСТЯ 10 ЛЕТ
15:13
ЗЕ МАККЕРС
Рет қаралды 154 М.
Hisense Official Flagship Store Hisense is the champion What is going on?
0:11
Special Effects Funny 44
Рет қаралды 2,5 МЛН