Nonlinear Regression in Python

Поділитися
Вставка
  • Опубліковано 8 лип 2024
  • A three parameter (a,b,c) model y = a + b/x + c ln(x) is fit to a set of data with the Python APMonitor package. This tutorial walks through the process of installing the solver, setting up the objective (normalized sum of squared errors), adjusting the parameter values to minimize the SSE, and plotting the results.
  • Наука та технологія

КОМЕНТАРІ • 38

  • @JuliusTanuwijaya
    @JuliusTanuwijaya 5 років тому +1

    hi! thank you very much for this video! that's help me a lot! THANKKKKSSSSSS!

  • @keithwald5349
    @keithwald5349 7 років тому +3

    Hi, Thanks for the nice video. I realize that the model is nonlinear in the predictor variable, x, but it is still linear in the parameters a, b, and c. So I think technically it is a linear regression.

    • @apm
      @apm  7 років тому +1

      +Keith Wald, you are correct. Although this example is linear in a, b, and c, the APM Python module can handle nonlinear equations and differential/algebraic/mixed integer variables for regression or other general nonlinear optimization problems. Here is some additional content: apmonitor.com/do. Thanks for your insightful comment.

    • @jhurd23
      @jhurd23 5 років тому

      Generalized Linear

  • @ZimoNitrome
    @ZimoNitrome 6 років тому +1

    What does the minimize part imply? Is it important?

    • @apm
      @apm  6 років тому

      Yes, the minimize part is important because it tells what objective function to judge possible candidate solutions. The solver tries to find the lowest possible solution (best sum of squared errors).

  • @TheGroundskeeper
    @TheGroundskeeper 6 років тому +3

    This is another example of great info shrouded by poor audio. Would really like to see more videos like this with a different audio track. jeeeez

    • @apm
      @apm  6 років тому

      I upgraded my microphone with a studio quality device about a year ago. I'm remaking some of the videos soon.

  • @SergioAlejandroPovedaCuevas170
    @SergioAlejandroPovedaCuevas170 5 років тому

    Hi Keith, thanks for the nice video. I try to use the same code but I changed some input parameters. I'm trying to fit, using this equation y = 1/(1 + 10^(a*(xm-b))), but the solution of a and b every time for different data is equal to 1, and it is wrong. Do you know what kind of changes should I do in the code or in the model.apm file?

    • @apm
      @apm  5 років тому

      Please see additional tutorials at apmonitor.com/che263/index.php/Main/PythonDataRegression (Scipy or Python GEKKO) or apmonitor.com/do I don't know Keith...but thanks for your comment.

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

    Thank for the great video, i have a small question. how and why do you choose the equation y = a + b/x + c ln(x)

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

      It can be any equation. If you use machine learning then the algorithm decides the model form: apmonitor.github.io/data_regression See module on regression.

  • @ahndonghyun214
    @ahndonghyun214 6 років тому

    Thanks for the video.
    i have one question about model.apm file.
    How can I enter Euler's number in Equations?

    • @apm
      @apm  6 років тому

      Here is a list of functions in APMonitor: apmonitor.com/wiki/index.php/Main/Equations You can get Euler's number with exp(1).

  • @lsqq007
    @lsqq007 7 років тому

    I have a little question. What exactly is the server needed for, and is it possible to do it without the server, or are there any options to do this on the local machine? Since I am a beginner in python it may sound like a silly question but thanks in advance

    • @apm
      @apm  7 років тому

      Yes, there is a server that you can download for Windows or Linux. Windows: apmonitor.com/wiki/index.php/Main/APMonitorServer Linux: apmonitor.com/wiki/index.php/Main/APMonitorServerLinux Both are a little complicated to install so most users just use the public servers for solutions.

  • @000Ameth000
    @000Ameth000 5 років тому

    First of all I want to thank you for your videos, that are very very useful.
    I have a slightly different problem. I have a differential equation describing the Monod growth model that is:
    dSdt = (-Mu/Y)*[Y(S0-S)+X0]*[S/(Ks+S)]
    where:
    S is the substrate (S0 the given initial condition)
    X0 is the initial condition for microorganisms
    Mu, Y and Ks are the parameters to find
    In this case, I have both derivative (dSdt) and variable (S) but I do not have time explicit in the equation. My data set is S vs time.
    Question 1) how can I use your approach to solve the Monod problem?
    Question 2) how can I modify the script when I need to add more differential equations and hence more parameters?
    Thank you in advance!

    • @apm
      @apm  5 років тому

      There are examples that are related to your problem here: apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization See #16 (dynamic parameter estimation), #8 (solve differential equation), and #11-13 (optimal control problems). I recommend GEKKO as a Python package for this type of problem. There is a webinar tomorrow at 11 AM EDT (8/23/2018) if you want to join the interactive session: apmonitor.com/wiki/index.php/Main/ApplicationWebinars or just see the overview: ua-cam.com/video/bXAkr7MPf4w/v-deo.html

    • @000Ameth000
      @000Ameth000 5 років тому

      Thank you! I will check the links and I will try to attend the webinar

  • @user-gz8ir1fr9d
    @user-gz8ir1fr9d 8 років тому

    excuse me did you have any films for teaching integration?I checked your page but I don't find.

    • @apm
      @apm  8 років тому

      Here is a video on integration ua-cam.com/video/4grhQ5Y_MWo/v-deo.html You can also see other content at the course web-site: apmonitor.com/che263/index.php/Main/CourseSchedule

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

    Hi thank you for your great explanation, but how do we choose the correct equation for our dataset.

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

      Machine learning (regression) builds the form for you. See apmonitor.github.io/data_science Otherwise you'll need to look at the data and make a judgement based on intuition. It is always good to start with linear.

  • @rodiluka2580
    @rodiluka2580 4 роки тому +2

    Hello! Do you know if i can do it with 10 parameters and only one equation. Xm and ym are already on those ten. I have been trying to do the same thing you did and it works until the graph appears, which only shows one point with the coordinates (1,1).

    • @apm
      @apm  4 роки тому

      I'd recommend Python Gekko instead of APM Python. It is easier to work with: apmonitor.com/che263/index.php/Main/PythonDataRegression (see GEKKO solution). If you want to post your code, please create a new question on StackOverflow with tag [gekko]. stackoverflow.com/questions/tagged/gekko

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

      APMonitor.com So I use that file instead of the apm file or I put my parameters there? Thank you

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

      @@rodiluka2580 with Gekko, you don't need to create an apm file. All of the coding is done directly in the program script. Please see the video and source code at the link I sent.

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

    I have a small question how do we deal with if the x axis is date?

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

      You can also plot something where the x values are dates. Try plotting a pandas dataframe with the date as the index.

  • @mostafatarek7110
    @mostafatarek7110 6 років тому

    What if x is not just vector but multiple vectors or multiple features
    So if x.shape== (100,3) then x has 100 examples and 3 features

    • @apm
      @apm  6 років тому

      This isn't a problem - you can have as many features as needed. You just need to add additional columns to your data file and include the parameter names in the model file.

  • @luziadossantossouzaneta7382
    @luziadossantossouzaneta7382 5 років тому +1

    How can I do the curve's derivate?

    • @apm
      @apm  5 років тому

      There is a finite difference package in misc.derivative docs.scipy.org/doc/scipy/reference/generated/scipy.misc.derivative.html or you can use Sympy to find an analytic derivative.

  • @JuliusTanuwijaya
    @JuliusTanuwijaya 5 років тому +1

    what if i want use "mean"? how?
    thank you

    • @apm
      @apm  5 років тому +1

      You could divide the objective function by the number of data points if you want to minimize the mean difference instead. However, it will result in the same solution because you are just scaling the objective function by a factor (number of data points).

    • @JuliusTanuwijaya
      @JuliusTanuwijaya 5 років тому +1

      @@apm thank you sir