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!
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!
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
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!
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!
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 ...
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?
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.
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
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.
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?
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.
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.