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

Non-Linear CURVE FITTING using PYTHON

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ส.ค. 2019
  • A tutorial on how to perform a non-linear curve fitting of data-points to any arbitrary function with multiple fitting parameters.
    I use the script package and the script.optimize.curve_fit function to perform an exponential fitting of data-points.
    Documentation:
    docs.scipy.org...
    Code shown in the video:
    www.bragitoff....
    Hope you find it useful!
    Follow me on:
    FB Page: / bragitoff
    FB Profile: / ducktape07
    FB Page2: / physwhizforum
    IG: / ___physwhiz___
    IG2: / ducktape07
    BLOG: bragitoff.com
    FORUM: physwhiz.bragit...
    ANDROID APPS:
    CrysX: www.bragitoff....
    Others: play.google.co...

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

  • @msm932
    @msm932 3 ปีที่แล้ว +14

    I saw at least five tutorials by now, asked three questions on stack-overflow cause that stuff never worked with my function. And finally I found a fellow scientist who gives this marvellous tutorial on curve fitting. Thank you a thousand times, it works!

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

      Did you gibe him a sub and like? 😇

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

      Same as I, this video answered all my questions.

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

    Bless your soul, this was excellent. I was able to find non-linear relationships between temperature and electrical load of a city, for electricity load forecasting. THANK YOU!

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

      I'm glad you found it useful 😊

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

      How do you decide the best initial guess I also want to find a relationship between droplet diameter and height, but the r2 value is around 0.48 so how can I improve thank you

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

    Thank you very much, friend, I've been suffering for two days what you can't imagine to achieve something like this.

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

    Dude your a god that was so well explained! Love you!

  • @Magnuomoliticus
    @Magnuomoliticus 3 ปีที่แล้ว +7

    Thank you very much! I hope I can help any viewer with this other tips.
    # In this example, if you want to know the errors of the fitting parameters "a" and "b" you can add this line to your code:
    a, b = np.sqrt(np.diag(pcov))
    # If you want to know the r^2 score of the fit, use this lines in your code:
    from sklearn.metrics import r2_score
    r2 = r2_score(yData, func(xData, *popt))
    I wish you the best of lucks!

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

    absolute hero so much better than online forums/documentation explenations

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

      Glad you think so!

  • @Alex-oh1wt
    @Alex-oh1wt 2 ปีที่แล้ว

    what an absolute legend

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

    U saved my life

  • @Anuraag-oh5eb
    @Anuraag-oh5eb 3 ปีที่แล้ว +5

    lovely content! thank you. but your plot .. talk about overfitting the data :D :D :D

  • @mandarbopardikar9135
    @mandarbopardikar9135 3 ปีที่แล้ว

    Awesome!! This helped me a lot.

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

    thx sir
    that was helpful :)

  • @aaronlopes5256
    @aaronlopes5256 3 ปีที่แล้ว

    Thank you...simple and effective

  • @sunday-thequant8477
    @sunday-thequant8477 3 ปีที่แล้ว

    Thanks man! Very simple code.

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

    Thanks for this nice tutorial. I have a question. How can I calculate the r2 (r-squared) of the curve fit? Is there any way to convert the pcov to r2? THANKS!

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

    Is it possible to choose the size of the y-axis? I mean, my experimental y values are very little and i want the graph only to show them in comparision with the curve fitting ...

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

    sir kindly make video on improve the goodness(reduce SSE) of fitting curve, thank you

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

    Thanks for the help :))

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

    How do you find the R squared value?

  • @oxydol3456
    @oxydol3456 3 ปีที่แล้ว

    interesting topic. thanks.

  • @MrGreen_N
    @MrGreen_N 3 ปีที่แล้ว

    Well done, thank you

  • @NovaWarrior77
    @NovaWarrior77 3 ปีที่แล้ว

    THANK YOU SO MUCH!!

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

    how to get error ...??

  • @ahmedroumi2512
    @ahmedroumi2512 3 ปีที่แล้ว

    How can we compute the area under curve ( for exemple for an asymetric gaussian )

  • @MM-vw1ck
    @MM-vw1ck 3 ปีที่แล้ว

    I have this problem, where the data I'm trying to fit is not of polynomial/exponential form.

  • @Gustavo_0107
    @Gustavo_0107 3 ปีที่แล้ว

    Thank you for the video! I have one question, how do I determine the uncertainty of the coefficients generated by the curvefit?

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

    i got error saying " ImportError: cannot import name 'read_arguments' from partially initialized module 'popt' " could you please help?

  • @addons01
    @addons01 3 ปีที่แล้ว

    I have a question, how can you predict using the curve_fitted function for a specific value but no array, which isn't part of the dataframe? Let's say the x value is 6 and a prediction for this number is needed.

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

    Can u do a curve fit with more than one curve, example u have 2 function/model with same parameter and u want to fit those curves with 2datas u have of that function respectively, maybe u can weight the residual of the curves?

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

    hi Mr., How do I know which initial values to consider for the initial conjecture of the parameters?
    I will be grateful for the answer

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

      Just an educated guess is usually enough. If you're modelling something you might have an idea about what to expect. In some cases even bad initial guesses may converge. If not then just try another one randomly if you have no odea about what to expect.

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

      Each problem has a method to get initial values. In Process Simulation you must know where do you com from and what do you espect. There no exists a general method o mathematics for the initial value. Cheers

  • @sheetanshudeepak8779
    @sheetanshudeepak8779 3 ปีที่แล้ว

    thanks sir

  • @JpmestraoPSN
    @JpmestraoPSN 4 ปีที่แล้ว

    thanks

  • @Alpharabius99
    @Alpharabius99 3 ปีที่แล้ว

    How can we get the equation for curve?

  • @juandiegobohorquez8238
    @juandiegobohorquez8238 3 ปีที่แล้ว

    Do you know if it is possible to use scipy functions instead of defining the fitting function yourself? That is, for example, if I want to make a fit my data with lognormal or power law equation, do I have to write it explicitly and change the parameters for each?

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

      This is the most automatic it can get if you want to do meaningful science. We only need to define a fitting function here which we do so by considering the type of problem we are considering.

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

    Thank you so much for explaining in details. Can you explain why you wrote a=%5.3f, b=%5.3f in line 28 of your code?

    • @PhysWhiz
      @PhysWhiz  3 ปีที่แล้ว

      It means it will print a floating point number with 5 characters, with 3 digits after the decimal point. It is just for formatting the output.

  • @shahinsharafi5062
    @shahinsharafi5062 3 ปีที่แล้ว

    I tried to do same code, however python did not sketch the curve for me !

  • @HS-ii9dj
    @HS-ii9dj 4 ปีที่แล้ว +1

    Hi, would you be able to help me I'm trying to fit a curve_fit through my data but it's not working?

    • @PhysWhiz
      @PhysWhiz  4 ปีที่แล้ว

      Is the code running? Since the curve_fit method requires an initial guess, so that may be the reason if the optimization doesn't converge. You can try different values for initial guess.

    • @HS-ii9dj
      @HS-ii9dj 4 ปีที่แล้ว

      The code does run and give a straight line , I have guessed the slope and intercept do I also need a start_slope and start_intercept?

    • @PhysWhiz
      @PhysWhiz  4 ปีที่แล้ว

      You want to do a linear fit?

    • @HS-ii9dj
      @HS-ii9dj 4 ปีที่แล้ว

      yeah a linear one , shall i send you my code?

    • @PhysWhiz
      @PhysWhiz  4 ปีที่แล้ว

      Although the video is for non-linear fitting, you can still do linear fitting by modifying the func as:
      def func(x,m,c):
      return m*x+c

  • @HS-ii9dj
    @HS-ii9dj 4 ปีที่แล้ว

    can I still use curve_fit if I have errors in x but not in y?

    • @PhysWhiz
      @PhysWhiz  4 ปีที่แล้ว

      Good question. curve_fit may not be the best choice in such a case. You may wanna try odr from scipy.

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

    Can we do this on real dataset?

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

      It depends on the amount of noise that your data might have. Also, if you have an idea about the what mathematical relationship should it follow.

  • @kartikanand6348
    @kartikanand6348 4 ปีที่แล้ว

    I would prefer you to speak in your original accent, please

  • @arslan809
    @arslan809 4 ปีที่แล้ว

    bhai tu gora nhe hy pr koshish poori kr rha hy k wsa boly mgr nhee
    You know, You know kam bola kr

    • @AV-tr9hl
      @AV-tr9hl 4 ปีที่แล้ว

      what ??

    • @sanket5050
      @sanket5050 4 ปีที่แล้ว

      But what’s your problem