Just the fact that you provide this invaluable content for free, when others are selling low quality courses for a lot of money, proves how a great human being you are. You are a true Master.
thanks for the help this was a long long journey it took me like 3-5 hours to translate my german function name in its actual english equivalent since the direct translation is miles miles away :D and finaly i got a model that should help me solve my enzyme activity measures
Hi! Great video! A couple of questions: 1) What if you had multiple people's heart rate? Is it possible to create a curve that would fit all of them? 2) What if we do not have the BPM equation? Thank you!
Yes, just add the other people to the objective function. You'll likely need a nested loop inside the objective function. The objective function is a single number so all the sum of squared errors are lumped into one value.
6:26 whats the formula really that you have used in that bpm fn ? i didnt understand that part. usually what I know is that therea re various non-linear methods that one can choose for non-linear reg types such as polynomial fits , lograthmic fits and so on . correct me if I am wrong pls
Check out 3:58 for the correlation that is used in the bpm function. There are many different types of nonlinear functions that can be used or even machine learning where something like an LSTM can predict time-series data. Here is more information on machine learning approaches: apmonitor.com/pds There is a regression module that may help in particular: apmonitor.com/pds/notebooks/06_regression.html
very good tutorial, however my doubt is what if you have a matrix of parameters? how do you make the objective function. eg: Ax = b. I need to find A. how do you frame the problem?
You may want to use Gekko for that problem: apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization Check out the matrix operations with Gekko: github.com/BYU-PRISM/GEKKO/blob/master/examples/test_arrays.py
If you don't know the non-linear equation, try using regression with Machine Learning: apmonitor.com/pds/index.php/Main/RegressionOverview The lazypredict package in Python helps evaluate the regression on multiple models. Otherwise, try different functional forms that you design.
So for non linear regression we have to assume/guess which curve equation will fit the data and unlike linear regression in PYTHON which predicts itself??
The parameters are single values so there is no covariance between them. If you have a high degree of covariance between data (x, y), it means that the two variables have a strong linear relationship. If one goes up, the other also goes up (or down).
No, you can add simple upper and lower bound constraints to variables in Scipy curve fit but not more complicated bounds that involve two or more variables. There is also scipy.optimize.minimize and python gekko that support these types of constraints: apmonitor.com/che263/index.php/Main/PythonOptimization
Thanks for the demo, very useful for a beginner like me! managed to do something similar following the steps. I wanted to ask something. My formula in stead of having a single variable ( time), y have 3 input variables, i have to compute p1[i], p2[i], p3[i] to be able to calculate the y value. I manage to adapt my code to that and plot it, but i got stucked in the curve_fit. In the curve_fit uses only 1 xdata if i am correct. What variation can i use? I hope you know, thanks !
They are guess values. If it doesn't converge with guess values of 1 or 0 then I sometimes create a plot and adjust the values myself until the predicted gets closer to the data. Vanishing gradients or local minima can be a problem with poor initial guess values.
is there iany way to solve equations in a python list [eqn1,eqn2,eqn3.........] with adition constainsts in form of equations e.g. a+bX=90, a*X^2+b*X=100, like in regression we have a model, if we substitute data points in it we will get many equations of model parameters along with it we add additional constaraints please help me
Yes, please see apmonitor.com/me575/index.php/Main/NonlinearRegression as an example of this type of problem where you have an objective and constraint with data regression.
Hi, this was very helpful. However, if you had a dataset that comprises of multiple exponentially decaying curves, how would this work out? I can relatively do this for a single exponential decay curve but unsure on how to deal with multiple exp. decay curves.
You can add additional variables and equations to the model. It is no problem to have any number of variables and equations. There are additional tutorials on regression here: github.com/APMonitor/data_science/blob/master/06.%20Regression.ipynb
Hi, that was awesome and very helpful! Just one question, when you entered c, cov where was the cov used? Only c was printed out, right? If I enter just c in place of c,cov would there be any difference? If you can attach a link for the same, that would be great. Thanks a bunch
Yes, you can look at the error or R^2 value when you adjust only one of the parameters at a time. Here is another example: apmonitor.com/me575/index.php/Main/NonlinearRegression You can turn the status to off (0) for any of the parameters that you want to hold constant.
hello sir , is there any similar package in python as curve fit , in which we can able to impose some constraints ( just like during regression at a particular point slope should be a specific value for continuity ) during regression, OR is there any posiblity in curve_fit to impose some constraints
@APMonitor.com sir , I have X and Y data, in which first ranga of data fits in certain equation and next range of data fits in some other equation, I used scipy.curve fit first set of data to non linear equation, for second set of data to be fitted in second equation , I need the regressor to follow the constraints, 1. at the break point / trasnsitiin point of frist equation to second, the value of y(x) two equation should be same, 2 . and also slope of equation one and two at that transition point should also have to equal , so I have to use this constraint during fitting of second range of data to the second equation , what I understood minimize () is not a regressor ,, a equation solver, and in GEKKO I don't know how to impose those constrains, please give a help or suggession, Hope you aware of maple, in that 'LSSolve ' was there to docl this regression with constraints, I need a similar function or package in phython to do curve fitting with user defined contraints
@@KarthikeyanMmmm you can switch equations with one equation with 0=b*(eqn1)+(1-b)*(eqn2) with b=1 when eqn1 is active and b=0 when eqn2 is active. You can set the derivative equal at the switch point with (s*(eqn1.dt()-eqn2.dt())==0) where s is the switch point that is 1 when there is the switch. Please see apmonitor.com/do for additional examples. If you have questions as you get started, please post a complete and minimal example to StackOverflow with tag [gekko].
Thanks for the very clear video. However, it doesn't seem to work for my specific function: after defining variables x and y using x.values as in the video at 10:56 from a datafile, I try doing curve fit and it tells me that "only size-1 arrays can be converted to python scalars", which I am unable to fix. All the other steps are the same as in the video This is the function I am trying to fit: y = c_1 * x^{c_2}
Hello please. I have done everything in your video. It works every well. But how can I predict the heart rate for the time out of the range? I mean what is now the prediction function I have to call??? Please help me for this task.
if i know the predicted curve z_pred = x*y after some matrix transformations and i know the actual value z_actual then if i find MSE(z_actual - z_pred) then how can i reduce this error? Anyone can answer
If the solver reports a successful solution then it is at least a local solution. Try different initial guesses or try a different solver such as Python Gekko: apmonitor.com/me575/index.php/Main/NonlinearRegression
They are initially just guesses. With the solver, they are selected by the optimizer to minimize the difference between the predicted and measured values.
You can either select a form yourself based on knowledge of the system (linear, nonlinear, exponential, logarithmic, etc) or else use concepts from machine learning to determine the correlation. For ML content, see apmonitor.com/pds (Regression section).
Thank you very much for your video! By the way, is anybody know how to solve the same issue, but when you have more than one variable. For example Y = a * x1^b + c*x2^d. We have dataset with x1,x2, Y. And how we can optimize a,b,c,d?
It uses a gradient descent. There is step-by-step code here: apmonitor.com/me575/index.php/Main/QuasiNewton There is also an optimization textbook that details the methods: apmonitor.com/me575/index.php/Main/BookChapters
@@apm so when using ML libraries , python automatically uses one of the approximation principle to find out the global maximum/ minimum ? I mean we don't need to create a function for example to do gradient descent approximation....
In most cases you can just use an initial guess of 0 or 1 for all values. In this case, the problem is very nonlinear so it requires a better initial guess. A good way to come up with the initial guess is to try values until the predicted and measured values are close. An optimizer can then find the best parameters if you start with a good initial guess. Sometimes you also need to add bounds to the parameters to get it to converge. A better solver can also help. Here is a tutorial on Python Gekko: apmonitor.com/che263/index.php/Main/PythonDataRegression
Hi, I am trying to fit my data with SIR model. Is there any suggest for fitting the data with ODE equations with two coefficients (reaction rate constant)? Thanks in advance.
@@apm This seems very promising howerver the documentation is not clear how to get started. Perhaps I am making things overly complicated, however I have yet to see any examples in Python or R that will generate the curves shown in Wikipedia. This seems "simple" but apparently it isnt. en.wikipedia.org/wiki/Quantile_regression