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)
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.
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
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.
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.
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.
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.
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
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.
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)
You are killing it. Thanks for the thorough explanation
That was a great explanation. Thanks a ton!
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)
That was very helpful and clear, thank you
That was very helpful! Thank you!! :)
Thanks, finally I understood difference between polyfit and poly1d, I was just wondering why they use 2 functions...
it was very useful. thanks!
That helps a lot, thanks
Very helpful!!
good explanation
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.
hello! I need to get the potential and logarithmic equation from a data table, what command can I use instead of polyfit?
thanks!
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
the pythonic way to create an array with the values from 1 to 20 is [x for x in range(1,21)]
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.
Thanks
So cool
Can you use this curvfit for statistical fitting, like Normal dist/ exponential dist/ ... instead of the deg 2?
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.
Muy interesante el video. Qué editor utilizas?. En todos los editores es posible usar esta funcion?
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.
tysm
great
thks a lot
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.
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
Thank you sir
What if the x axis is date? How can i deal with in this case?
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.
Hi, how would you do this using data in a pandas data frame of two columns please?
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
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.
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)
@@AMGaweda Thanks for the reply man. Wasnt expecting :). İ will post again after i try it.