Curve Fitting using Numpy's Polyfit Function

Поділитися
Вставка
  • Опубліковано 5 кві 2020

КОМЕНТАРІ • 34

  • @pgille2
    @pgille2 2 роки тому +2

    You are killing it. Thanks for the thorough explanation

  • @j8ahmed
    @j8ahmed 3 роки тому +5

    That was a great explanation. Thanks a ton!

  • @standman007
    @standman007 7 місяців тому

    This was extremely helpful. I verified with excel and my equations match perfectly. Thanks, from the bottom of my heart. with value of 1 i got the same Linear equation. with value of 2 i got the same Polynomial equation - for example curve = np.polyfit(x,y,1)

  • @atolantis
    @atolantis 3 роки тому +1

    That was very helpful and clear, thank you

  • @somecrispywater1146
    @somecrispywater1146 3 роки тому +1

    That was very helpful! Thank you!! :)

  • @alice-gv5ue
    @alice-gv5ue 3 роки тому

    Thanks, finally I understood difference between polyfit and poly1d, I was just wondering why they use 2 functions...

  • @nedasadati6385
    @nedasadati6385 2 роки тому +1

    it was very useful. thanks!

  • @martinx1783
    @martinx1783 2 роки тому +1

    That helps a lot, thanks

  • @dm3248
    @dm3248 3 роки тому +1

    Very helpful!!

  • @mohammedthahaabdulshukoor4321
    @mohammedthahaabdulshukoor4321 4 роки тому +1

    good explanation

  • @keshav347
    @keshav347 2 роки тому

    Could you please explain how i can use this function if i have 3 dimensions [x,y,z] how can i fit a curve in 3d. as i would like to compute the radius of curvature by fitting a curve. Thanks in advance.

  • @tony_joris
    @tony_joris 3 роки тому

    hello! I need to get the potential and logarithmic equation from a data table, what command can I use instead of polyfit?
    thanks!

    • @AMGaweda
      @AMGaweda  3 роки тому +2

      My biggest recommendation would be to look through NumPy's documentation: numpy.org/doc/stable/reference/routines.polynomials.html which may point you to the the particular equation you're looking for. If it is not there, then I'd recommend looking into other Python libraries that may do. Worse comes to worse, there's always the "build it yourself" approach

  • @dontaskme1625
    @dontaskme1625 3 роки тому

    the pythonic way to create an array with the values from 1 to 20 is [x for x in range(1,21)]

    • @AMGaweda
      @AMGaweda  3 роки тому +1

      While [x for x in range(1,21)] will create the 1 to 20 list, I would not consider it the "pythonic way". Plus, for many students, they've only recently learned about lists, so adding a one-line trick for creating lists, while nice, can be confusing to some students. Its not to say you shouldn't do it, but when teaching a separate concept, its better to reduce extra complexities.

  • @felipeemerson4050
    @felipeemerson4050 4 роки тому +1

    Thanks

  • @tomgt428
    @tomgt428 3 роки тому +1

    So cool

  • @joacimjohnsson
    @joacimjohnsson 3 роки тому

    Can you use this curvfit for statistical fitting, like Normal dist/ exponential dist/ ... instead of the deg 2?

    • @AMGaweda
      @AMGaweda  3 роки тому

      Polyfit is a "least squares polynomial fitting" algorithm, so you are able to increase (or decrease) the curve's degree as necessary. It will not do this for you, but you can adjust the number or add more code that checks the curves precision.

  • @Ingeniosamente
    @Ingeniosamente Рік тому

    Muy interesante el video. Qué editor utilizas?. En todos los editores es posible usar esta funcion?

    • @AMGaweda
      @AMGaweda  Рік тому

      Disculpas por el lenguaje, estoy usando Google Translate. Utilizo GIMP con una tableta Wacom para dibujar en mi pantalla: mi paleta de colores se creó a partir de FlatUIColors.com (v1) y mi pincel es `Hardness 100` tamaño 2 con Smooth Stroke habilitado y configurado en 20. Para grabar videos, uso OBS (obsproject.com/) sin ninguna otra edición de video. Tengo mis botones F8 y F9 configurados para iniciar y detener la grabación. En este video, usé Spyder para la programación configurada desde la distribución de Anaconda (anaconda.org/), pero en el pasado también usé otros editores de texto. También uso Sublime Text con complementos de autocompletado de Python, pero VS Code también puede funcionar.

  • @Justin-yc5jt
    @Justin-yc5jt 3 роки тому +1

    tysm

  • @kaaehtla
    @kaaehtla 3 роки тому +1

    great

  • @yousfoss4367
    @yousfoss4367 3 роки тому

    thks a lot

  • @aritraray2501
    @aritraray2501 3 роки тому

    Hello, how can I find the area inside a curve?
    I have data points for a hysteresis loop and I want to calculate the area inside the curve.

    • @AMGaweda
      @AMGaweda  3 роки тому

      You'd want to look into the SciPy's Integrate function; here is a video that might help ua-cam.com/video/zKKfw1WkUt4/v-deo.html

  • @SomeOne-rx2xw
    @SomeOne-rx2xw 2 роки тому +1

    Thank you sir

  • @Soo5301
    @Soo5301 3 роки тому

    What if the x axis is date? How can i deal with in this case?

    • @AMGaweda
      @AMGaweda  3 роки тому

      In this case, you'd need to create a normal list from 0 to how ever many dates you have in mind. Think of this like a graph in math class - you still need to specify what the x-axis in your graph is (even if its dates). If you then need to plot the graph, you can modify the x-axis's display with MatPlotLib's set_xlabel function.

  • @abigailwaring4720
    @abigailwaring4720 2 роки тому

    Hi, how would you do this using data in a pandas data frame of two columns please?

    • @AMGaweda
      @AMGaweda  2 роки тому +1

      The quickest way I've found to extract a list from a DataFrame is to do something like x = list(df["x"]). Then you should be able to use the approach from the video

  • @Alpharabius99
    @Alpharabius99 3 роки тому

    What if i want to plot variable data sets of x but with the same y axis.
    İmagine 10 data sets of x's and one data set of y. İts like one data set of x toone data set of y in the video.
    But what if i want to fit the curve for various data sets of x axis with only one y axis? Ofcourse i can do it one by one. But there should be some quick way to do this right?
    İt seems pointless to run this code for 10 times for different x Data sets.

    • @AMGaweda
      @AMGaweda  3 роки тому +1

      My thoughts are that you could use a for loop to change your x, curve, and plot with your y outside of the loop. Something like:
      datasets = [[123],[4,5,6],[7,8,9]] # your X datasets
      y = [1,2,3] # your Y
      for x in datasets:
      curve = np.polyfit(x, y) # creates your curve on each X one at a time
      poly = np.poly1d(curve) # makes that curve an np.array
      # plot your datasets
      plt.show() # outside the for loop
      This would condense your code to only need to do the calculations "once" for each X dataset along the same Y. Also, since plt.show() is outside the for loop, all of your plotting would be done on the same graphic (you could also use subplots here instead depending on what you are looking for)

    • @Alpharabius99
      @Alpharabius99 3 роки тому

      @@AMGaweda Thanks for the reply man. Wasnt expecting :). İ will post again after i try it.