ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

Curve Fitting in Python (2022)

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ส.ค. 2024
  • Check out my course on UDEMY: learn the skills you need for coding in STEM:
    www.udemy.com/...
    In this video I show how to use the curvefit function in the scipy.optimize library. I also look at practical examples from physics.
    Tutorial Playlist:
    • The Full Python Tutorial
    Code:
    github.com/luk...
    Discord:
    / discord

ความคิดเห็น • 107

  • @hakansert13
    @hakansert13 2 ปีที่แล้ว +24

    Sometimes one may both know coding and physics but it becomes really exhausting to combine them together; you may not able to know where to start... You are directly attacking to that tricky intersection perfectly and that is exactly what is needed for lots of science students/academics!
    I just personally wanted to thank you for such great videos as a PhD student in physics who had worked with paper and pen for years but needed numerical computation eventually. Your videos are awesome and very informing! I hope you keep going.

    • @skilz8098
      @skilz8098 ปีที่แล้ว +1

      If you ever try your hand at 3D Graphics Programming and write the underlying core components of the 3D Rendering Engine where you implement a Physics Engine with basic kinematics, collision detection systems, A.I. Path Finding Algorithms, etc. then you get into doing Animations, Particle Effects, Rigid Bodies, Rag Dolls, Liquid or Water Animations, etc... by using advanced shaders for many various lighting, shading, shadow, and other special effects... That's one of the best ways to merge the two fields.
      Now, this kind of Physics programming is different from Data Science, Equation Solver type Physics system, but it's a great place to start and most of the topics and transitions would already be covered. A basic 3D Rendering Engine or 3D Game Engine uses mostly linear algebra and trigonometry, but there is still a bit of calculus here and there such as when basic integrals, performing interpolations of various kinds, using runge kutta as well as FFTs all come in handy. Especially FFTs when working with Audio Processing and 3D Sound Environments is another great benefit.
      You end up incorporating many mathematical and physics, (maybe even a little bit of chemistry, biology, and environmental systems depending on the context of your Engine and what you are going to build with it) concepts into your Engine that stem across many software engineering and program application development disciplines by using almost every kind of container and associated algorithm there are out there. Other key features would be file management and file parsers, you can end up writing your own scripting or run time interpreted language, if doing multiplayer over networking then multithreading and multiprocessing principles, compression and decompression algorithms, encryption and decryption algorithms come in handy. Then you have many other topics such as batch processing, Storage or Assets Memory Managers, Many Various Shaders with an accompanying Shader Manager, and so much more. This doesn't even include things such as GUIs, HUDs and Font Management...
      Now, once you have the Engine Built with all of its core components (and I don't mean using a 3D engine such as Unity or Unreal...) Then the fun begins when you start building your game that is seperate from then engine but requires it as a core underlying library to function properly. Now imagine building a game like Factorio or Minecraft... Both of those games are Turing Complete... or even a 2D with 3D layer slices such as in Oxygen Not Included or a semi-factory but defense tower game like Mindustry which are both Turing Complete... or something similar to those... Then I think you can build just about any kind of software application that you could imagine except maybe an actual robust compiler-debugger-linker suite, or an actual Operating System... Oh they could be done... but they're a challenge. I found it was actually a bit easier to learn how to build a Hardware Emulator in C++ with a focus on the 6502 for the NES... Now that was a fun project as well! So almost anything is possible to build but it does depend on the limitations of your hardware...
      This is just a summary of about a 20 year journey of independent studying purely self taught hobbyist and some of the many topics I've learned over the years! There's many other things that I didn't mention as this is starting to become quite long... It's been a great journey. Even watching Ben Eaters 8-Bit Breadboard CPU series was a delight! So much so, that I actually implemented it in Logisim.

  • @mikhailbandurist8652
    @mikhailbandurist8652 2 ปีที่แล้ว +33

    That's the scientific channel that we need. Good sound (which is the most important), good picture, Chad-looking science guy (in movies smart people are often nerds with big glasses) and a good explanation - this is really nice! Thank you for video!

  • @vadympasko100
    @vadympasko100 11 หลายเดือนก่อน +3

    Absolutely love this intro to SciPy's 'curve_fit' function! Suggest you to make a video on spline fitting, which is included into SciPy's 'interpolate' module. With splines it is possible to find best fit to a really complex data, including those presented in this tutorial.

  • @crazyclown9914
    @crazyclown9914 2 ปีที่แล้ว +2

    Two weeks ago I had a physics assignment involving this method, which was a absolute disaster. This is why I should watch your videos as soon as they show up. Anyway, Thanks for the amazing job!

  • @python4scientists
    @python4scientists 2 ปีที่แล้ว +6

    Nice! Note that (in 19:40) you need to set absolute_sigma=True to get the absolute value errors on the parameters. A good example is using the known formulas to calculate the error on the parameters (A,B) of a strait line fit and compare with the results returning with absolute_sigma=False e absolute_sigma=True.

    • @boseongcho62
      @boseongcho62 2 ปีที่แล้ว +3

      It's a good comment

  • @heera_ai
    @heera_ai 2 ปีที่แล้ว +7

    Your initial guess was good enough 😂, great tutorial!

  • @otaviooliveira5157
    @otaviooliveira5157 ปีที่แล้ว +4

    The kind of detailed explanation i needed! The examples nailed it! Thanks a lot :)

  • @moona5454
    @moona5454 2 ปีที่แล้ว +2

    Great video. Especially focusing and repeating multiple times that our goal is the parameters and not just having a good fit! Parameters = Context = Reason why we're doing the fit

  • @rainycloud10
    @rainycloud10 ปีที่แล้ว

    This is exactly the tutorial I needed given I had to perform many counting experiments . I wish I had found this channel sooner before going insane over tutorials that made zero sense to me.

  • @MrAman47
    @MrAman47 2 ปีที่แล้ว +4

    Great video, just a little correction, as the physicist in me is happy to show himself every now and then: It's actually Lennard-Jones potential, sometimes also called Van der Waals potentials (dipole-dipole potential) big brother. I don't think there's a thing called Leonard-Weibeck potential reguarding atomic repulsion, but if there is and it's related to the LJ potential, let me know!

    • @MrPSolver
      @MrPSolver  2 ปีที่แล้ว

      Oh I might have misspoke! Thank you for this correction 😂

  • @RutgerHaan
    @RutgerHaan 2 ปีที่แล้ว +5

    Thanks a lot! This was a really thorough explanation which gave me everything I need to plot my data in a nice way :) Keep it up!

  • @j.abrahamhernandez3629
    @j.abrahamhernandez3629 2 ปีที่แล้ว +1

    dude your videos rock, i love the no-nonsense type of attitude when tackling things, cheers! (;

  • @alejandraacosta248
    @alejandraacosta248 ปีที่แล้ว

    Wow! You explain very clearly! I was fighting with my code since I did not understand how to work with curve_fit and you fell out of the sky! Thank you so much!

  • @maplesyrum
    @maplesyrum 6 หลายเดือนก่อน

    This is excellent content. Clearly explained a problem I've been having trouble grasping for months. Thanks!

  • @nathan6798
    @nathan6798 10 หลายเดือนก่อน

    Hi, first off EXCELLENT VIDEO THANK YOU SO MUCH
    Just for those who need this video, there are a couple of clarifications (sorry if you made them and I didnt notice), but its popt, pcov = scipy.optimize.curve_fit
    not just curve_fit () . Unless you made a shortcut beforehand
    Other than that , thank you again so much help !

  • @swatibhargava4140
    @swatibhargava4140 ปีที่แล้ว +1

    Super helpful and so nicely explained! Thank you so much for making this video! The multiple examples helped me a lot and in fact covered what I was as looking for!

  • @GabrieleIuzzolino
    @GabrieleIuzzolino 19 วันที่ผ่านมา

    Thank you! Your tutorials are very clear and useful!

  • @ragibabsarramon7881
    @ragibabsarramon7881 6 หลายเดือนก่อน

    Your Videos are really helping me. Thanks a lot.

  • @laurenceturpin1409
    @laurenceturpin1409 7 หลายเดือนก่อน

    Thank you for making this video I particularly liked that you gave more than one example.

  • @siddharthpachpor5928
    @siddharthpachpor5928 2 ปีที่แล้ว

    superb video with respect to physics and maths! Best application based explanation. Period. Please I request you to post such concepts with such physics based applications visualisation. I just feel blessed. Thanks a lot. tons

  • @nothingisreal6345
    @nothingisreal6345 ปีที่แล้ว

    Like 25 years ago i wrote code to fit multiple gauss function to some spectrum comming from Cherenkov radiation emitted from cristals. Those days everythibg had to be done in C/C++. I use the "Numerical recipies in C" book and lib and the Marquard Levenberg algorithm. Took 3 weeks to progam that (including some GUI and other stuff). Today with Scipy maybe one or two days... Some stuff actually get's better.

  • @loredo97
    @loredo97 ปีที่แล้ว

    Brilliant explanation of the covariance!

  • @Bored_Trumpet
    @Bored_Trumpet 8 หลายเดือนก่อน

    Was expecting a good description of what's going on with the curve-fitting functions, albeit with boring data. But actually I found exactly what I was looking for. Trying to get the photopeaks and their resolutions in a similar spectroscopy. Also the walking through cell-by-cell helps for digestion. Used to begrudingly use python, but after a semester I much more prefer it over finicky excel sheets.

  • @chayanikarabha8556
    @chayanikarabha8556 2 ปีที่แล้ว +1

    Thank you so much for making such videos. Specifically in physics. It is of so much help. Please keep doing such videos.

  • @danteng5651
    @danteng5651 7 หลายเดือนก่อน

    This is super clear!

  • @DEChacker
    @DEChacker ปีที่แล้ว

    awesome video as always. Learned a lot - especially the cov-Matrix was super helpful
    One note: It is the Lennard-Jones potential, not the Leonard Weibeck potential

  • @iurialmeida8979
    @iurialmeida8979 2 ปีที่แล้ว

    i found your videos about 10 minutes ago and mate, what an amazing content, you remind me of keith galli, he is awesome too

  • @gloryths
    @gloryths 2 ปีที่แล้ว

    You give quality out there. Respect man.

  • @mis_llaneous
    @mis_llaneous ปีที่แล้ว

    I learnt a lot from thus vedio, thanks bro👍

  • @dylanskinner6815
    @dylanskinner6815 2 ปีที่แล้ว

    Your videos are sweet! I found you earlier today and have already learned a ton. Thanks!

  • @abrahamdelacruz8389
    @abrahamdelacruz8389 2 ปีที่แล้ว +2

    Dude! this video is so useful! Great explanation and great material!

  • @boseongcho62
    @boseongcho62 2 ปีที่แล้ว

    Thank you now I understood how the errors behave!

  • @harveyjones5227
    @harveyjones5227 ปีที่แล้ว

    Amazing! Thank you. This has been perfect help with plotting an exponential curve to my data.

  • @ncarl2335
    @ncarl2335 3 วันที่ผ่านมา

    you gained a subscriber sir thanks

  • @JarredDavidson
    @JarredDavidson ปีที่แล้ว

    Excellent video. Very clear unpacking of the logic. Thank you! I've subbed.

  • @datastako156
    @datastako156 2 ปีที่แล้ว

    great videos! continue your greatwork bro! supporting from philippines here.

  • @monenehmoneneh9561
    @monenehmoneneh9561 ปีที่แล้ว

    perfect please do more in physcis and more intuitive

  • @MrSpaceboyy
    @MrSpaceboyy 2 ปีที่แล้ว

    This is great! Glad to find your channel

  • @rostamr4096
    @rostamr4096 7 หลายเดือนก่อน

    This is so very helpful...thank you

  • @chaitanyavarmamudunuri7270
    @chaitanyavarmamudunuri7270 ปีที่แล้ว

    Thank you for the content,
    I would like to see a video on hysteresis curvefitting with multiple conditions

  • @chaitanyavarmamudunuri7270
    @chaitanyavarmamudunuri7270 ปีที่แล้ว

    Thank you very much for such beautiful tutorials.
    Can you show fitting hysteresis models

  • @joaovictorbalieirodasilva1430
    @joaovictorbalieirodasilva1430 ปีที่แล้ว

    Please, make a numba tutorial :)
    Your videos are awsome

  • @AJ-et3vf
    @AJ-et3vf 11 หลายเดือนก่อน

    Great video! Thank you!

  • @raysu9853
    @raysu9853 2 ปีที่แล้ว

    Great video, thank you. Hope to see you @ UBC some day :)

  • @philtoa334
    @philtoa334 2 ปีที่แล้ว

    Very good ,very Useful very : )

  • @andresderudder9950
    @andresderudder9950 2 ปีที่แล้ว +1

    Great video ! I just finished a lab report last Saturday, this would been useful jajaja. I would like you to make a video about animations in python tool

    • @rainycloud10
      @rainycloud10 ปีที่แล้ว

      Same. I wish I had found this tutorial a couple of weeks ago for my lab reports. But better late than never.

  • @yazito21
    @yazito21 ปีที่แล้ว

    Very helpful video...👍👍👍

  • @vinrai09
    @vinrai09 ปีที่แล้ว

    Thanks for explaining this so well!! Super helpful!!

  • @antonXPS
    @antonXPS ปีที่แล้ว

    excellent explanation, very detailed

  • @andrewjolly319
    @andrewjolly319 2 ปีที่แล้ว

    Please consider doing some stuff on Bayesian inference using Markov Chains, maybe using the PyMC library?

  • @ayushisuman4889
    @ayushisuman4889 6 หลายเดือนก่อน

    Very helpful content. The error(as obtained from experiment) is sometimes not symmetric about the mean y position. Is it possible to encode that into curve_fit function?

  • @kapfox
    @kapfox 2 ปีที่แล้ว

    You definitely making a good thing, killing a Matlab!

  • @Raiden_Amani
    @Raiden_Amani ปีที่แล้ว

    Thank you so much !! You've been a really big help.

  • @minhangnguyen999
    @minhangnguyen999 ปีที่แล้ว

    OH GOD!!, thank you very much!!!!!

  • @Data_Handler-e6c
    @Data_Handler-e6c 26 วันที่ผ่านมา

    How to come up with the equation for curve fit method? Suppose the data doesn't follow a specific distribution which can be determined by seeing the scatter plot.

  • @Data_Handler-e6c
    @Data_Handler-e6c 26 วันที่ผ่านมา

    How to come up with the equation for curve fit? Suppose the scatter plot is not showing a particular distribution.

  • @senolkurt7864
    @senolkurt7864 4 หลายเดือนก่อน

    Thanks for the great tutorial. Since in real life we have only the data, how can we find the best non-linear model function that fits to our data?

  • @LOL-vt8jh
    @LOL-vt8jh 2 ปีที่แล้ว

    Good job!

  • @brucewernick6542
    @brucewernick6542 2 ปีที่แล้ว +1

    The heatmap of the covariance is brilliant, I'm definitely going to experiment with that. You mentioned the importance of the diagonal, but what do the other values in the covariance matrix mean?

    • @librealgerien
      @librealgerien 2 ปีที่แล้ว

      That’s how one parameter affects another if at all.

  • @skilz8098
    @skilz8098 ปีที่แล้ว

    Have you done any videos on FFTs or any Runge Kutta methods?

  • @rinezaman492
    @rinezaman492 2 ปีที่แล้ว

    These videos are really great

  • @GabrieleIuzzolino
    @GabrieleIuzzolino 19 วันที่ผ่านมา

    I'd like to ask you a question about the standardisation: why didn't you just multiply the ordinates by 10^(-21), in order to have numbers in the order of mangitude of 1?

  • @Heisenberg20023
    @Heisenberg20023 10 หลายเดือนก่อน

    I had a question, what if the function had constants in its definition that were an array that take certain values at specific points of xdata?

  • @colesmith2136
    @colesmith2136 2 ปีที่แล้ว

    Really great video!

  • @ahmedalshemi955
    @ahmedalshemi955 ปีที่แล้ว

    Thanks a lot for this nice explanation! I wonder what you use to fix one or some of the fitted parameters using the Scipy curve fitting function?

  • @romenaakter1042
    @romenaakter1042 2 ปีที่แล้ว

    Simply WOW!

  • @NaneRulz
    @NaneRulz 2 ปีที่แล้ว +2

    Great video!
    In the given case that you want to work multiple samples, and perform simultaneous fits. Is that possible? It is something I use often in XPS.

    • @ender84
      @ender84 2 ปีที่แล้ว +1

      Same question here. I have tried clustering without luck.

  • @lookaway8496
    @lookaway8496 ปีที่แล้ว

    Say I have a histogram plot with bars. I would like to do a skew norm fit to it. How do I proceed with this? can anyone help? like what initial data should I have

  • @STWNoman
    @STWNoman ปีที่แล้ว

    Perfect

  • @obliquesealray2188
    @obliquesealray2188 2 ปีที่แล้ว

    great vid

  • @frederic-louissauser6945
    @frederic-louissauser6945 2 ปีที่แล้ว

    pretty nice explanation, thanks! would it give some sense to use R or Scilab to achieve this, would it be more efficient?

  • @ksrajavel
    @ksrajavel ปีที่แล้ว

    Amazing

  • @gerrievanstaden3416
    @gerrievanstaden3416 2 ปีที่แล้ว +1

    Is there a way to do R^2?

  • @preshitlimje6046
    @preshitlimje6046 ปีที่แล้ว

    Hello Mr. P Solver,
    First of all a great video on optimization. I have a question regarding the optimization and identification of values in a given curve. Since I am completely new to this, I am not much aware of reverse engineering. I have an experimental Time-Temperature curve of a heat transfer system and based on it I need to identify the convective heat transfer coefficient. Is it possible to make it? if yes could you please give me an example. Thanks in advance.
    With Regards,
    Preshit

  • @ssj_hamood5364
    @ssj_hamood5364 ปีที่แล้ว

    For the Gaussian fit again. If I add a +c factor at the end in the gauss_f definition, will the plot work if I expand popt with c_opt so that the measurement points are taken into account which do not look "parabolic"?

  • @sadaf6295
    @sadaf6295 2 ปีที่แล้ว

    Sir, can u make video on Heisenberg spin chain and correlation between spins.

  • @yt-1161
    @yt-1161 2 ปีที่แล้ว +1

    where is the csv file ? @13:47

  • @miszcz310
    @miszcz310 ปีที่แล้ว

    Hmmm i was expecting something more clicking this video. When you have object returned by the fit method it has method called plot. It shows data with fitted model as well as plots the residuals.

  • @odvutmanush3234
    @odvutmanush3234 ปีที่แล้ว

    could you please show how to add bound to parameter?

  • @dominikrodak4204
    @dominikrodak4204 2 ปีที่แล้ว

    Hello, Thanks a lot for yours tutorials! They help me a lot. I have a question. How to use curve_fit (or how to cope with the problem) if I have a system of ODEs. How to use it as a model for curve_Fit function?

  • @rishiraj2548
    @rishiraj2548 ปีที่แล้ว

    👍💯

  • @MsJ0ni
    @MsJ0ni ปีที่แล้ว

    thank you..

  • @carlosyordanocozdelacruz3370
    @carlosyordanocozdelacruz3370 ปีที่แล้ว

    good video. How would I estimate the data based on those parameters?

  • @sarasachandrikabhavanivajj6592
    @sarasachandrikabhavanivajj6592 10 หลายเดือนก่อน

    I am getting the following error. I tried multiple methods like using numpy.asarray, np.array...... Is there any other solution?
    setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part.

  • @lospaturno
    @lospaturno 2 ปีที่แล้ว

    Can you tell something about fitting multiple gaussians in a signal?

  • @mohamadyusuf847
    @mohamadyusuf847 ปีที่แล้ว

    how to get that sample data, if i need

  • @03_bikramkesharipanda68
    @03_bikramkesharipanda68 ปีที่แล้ว

    Can we solve a multi-variable function through curve-fitting , for example - y = f(x1,x2,x3,x4)?

  • @KunalSingh-my5nd
    @KunalSingh-my5nd ปีที่แล้ว

    My values in y axis are all less than 1. So taking the sq root considering Poison statistics of photons gives very high error. What should I do ? Should i take some kind of scaling factor?

  • @Path_k_pradeep
    @Path_k_pradeep 2 ปีที่แล้ว

    Thanks 👏👏

  • @Science4Ever
    @Science4Ever 2 ปีที่แล้ว +1

    Great video as always!
    May I ask you to recommend some good books to dive further into this stuff? Maybe the ones you learned from, if any? It would be great!
    Keep doing these great videos, sir!

    • @jay89boy
      @jay89boy 2 ปีที่แล้ว

      ye im also wondering how did he reach all that knowledge

    • @Science4Ever
      @Science4Ever 2 ปีที่แล้ว

      @@jay89boy Same here, he might and actually should do a short video about giving some advices on how to dig deeper into the topic, especially book recommendations. He is a great guy and I think he will read this and respond in one way or another.

  • @khairulfahim
    @khairulfahim ปีที่แล้ว

    What is that algorith? I mean that is working in the background.

  • @bavneetkaur979
    @bavneetkaur979 ปีที่แล้ว

    Hello Mr. P solver, is there a way to solve for a complex function- meaning that the function that I have defrined returns complex(both real and imaginary parts) simultaneously, I tried doing it this with Scipy.optimize.curve_fit() but does not help If you have any idea pls share, thanks :)

  • @ricardoferes9051
    @ricardoferes9051 2 ปีที่แล้ว

    Hey could you do a tutorial for a CFD simulation in python?

  • @amelieeee9692
    @amelieeee9692 ปีที่แล้ว +1

    you left out a 2 in the gaussian formula

    • @assassingamer9088
      @assassingamer9088 7 หลายเดือนก่อน

      but when i plug in 2 it gives wrong answer. i tried it on my dataset. without it it gives right answer. why?

  • @bean217
    @bean217 ปีที่แล้ว

    This isn't at all related to the video content, but I have the same exact scar on my forehead

  • @TheGnarTube
    @TheGnarTube ปีที่แล้ว

    Your style annoys me but the content is good

  • @opm6278
    @opm6278 16 วันที่ผ่านมา

    this scipy shit hard to understand man.

  • @MultiMarty1987
    @MultiMarty1987 2 ปีที่แล้ว

    Great content. Just some feedback, I feel it would be less distracting if you didn’t show yourself talking while showing content on screen.