Regression with MATLAB fmincon

Ғылым және технология

A frequent activity in data science and machine learning is to develop correlations from data. By importing the data into MATLAB, data analysis such as statistics, trending, or calculations can be made to synthesize the information into relevant and actionable information. This tutorial demonstrates how to create a function that best approximates the data trend and analyze the result. A script file of the MATLAB source code is available at apmonitor.com/che263/index.php...

Пікірлер: 38

  • @hjnugget1974
    @hjnugget19743 жыл бұрын

    Very helpful, thanks! Couldn't get the constraints to work before watching this video :)

  • @konstapelwalander
    @konstapelwalander5 жыл бұрын

    Thank you so much for this great tutorial! Cheers

  • @apm

    @apm

    5 жыл бұрын

    You are welcome!

  • @helenos5578
    @helenos55783 жыл бұрын

    Thank you for this great tutorial

  • @cheekiestclan5668
    @cheekiestclan56683 жыл бұрын

    Good video, would it be possible to run a Simulink model within a loop, saving outputs to use as the data each time and change workspace variables to optimise how the model runs?

  • @raajgovindan
    @raajgovindan4 жыл бұрын

    Very well explained... Great... I have one doubt. How to verify that the optimized value is global optima not the local one?

  • @apm

    @apm

    4 жыл бұрын

    The methods I share use local optimizers. You could try a multi-start method where you give the local optimizer different initial conditions.

  • @abubakarizhar5608
    @abubakarizhar56089 ай бұрын

    Can we use fmincon with two independent variables. Also can you please show how to use fmincon for finding global minimum.

  • @azrulkiromil8885
    @azrulkiromil88854 жыл бұрын

    excuse me. thanks for the great tutorial. but, I want to ask something. in initial, there is the function y = p1 + (p2/x) + ln(x)*p3. is that equation an objective function for optimization? if it is so, what is the constraint? and, I think xm and ym can be plotted in excel file, so we shouldn't put xm and ym in MATLAB script. i.e. we import it from excel to MATLAB as an alternative. could it be? thank u so much.

  • @apm

    @apm

    4 жыл бұрын

    No, the equation is the constraint. The objective function is a measure of how well the data fits the predicted output (y) based on the input xm such as (y-ym).^2 Here is information on importing data files into Matlab: apmonitor.com/che263/index.php/Main/MatlabDataAnalysis It is easier if you save the file as a CSV type first.

  • @azrulkiromil8885

    @azrulkiromil8885

    4 жыл бұрын

    @@apm thank u so much for the answer, professor 👍👍👍

  • @navneetkumar6606
    @navneetkumar66063 жыл бұрын

    thankyou

  • @nontheness
    @nontheness5 жыл бұрын

    @15:23: Modifying line 27 from 'lb = ones(3)*0.2' to 'lb = ones(1,3)*0.2;' removes the warning message (Length of lower bounds is > length(x) ...).

  • @apm

    @apm

    5 жыл бұрын

    Thanks for the tip!

  • @trotion
    @trotion4 жыл бұрын

    Another great video! I commented extensively on one of your other videos. I have further narrowed it down to the following: I keep getting this error: "Error using fmincon (line 619) Supplied objective function must return a scalar value." I think its due to the fact that I have more than one set of xm and ym's, i.e. [xm, ym; xm, ym; ....;......]. Any comments?

  • @apm

    @apm

    4 жыл бұрын

    The error is because the objective function must always return a single number.

  • @niccolotani6828
    @niccolotani68284 жыл бұрын

    Great video I tried to use this code with a p(1) + p(2).*x+p(3).*(x).^2 and this error pops up Unrecognized function or variable 'getIpOptions'. Error in fmincon (line 822) options = getIpOptions(options,sizes.nVar,mEq,flags.constr,defaultopt,10,0.01); Error in Program1 (line 323) popt = fmincon(obj,p0); The code is the same as yours and i don't know what to do

  • @apm

    @apm

    4 жыл бұрын

    It sounds like it could be a problem with your MATLAB installation or compatibility of a toolbox. APMonitor MATLAB toolbox is another option if that doesn't work for you: apmonitor.com/che263/index.php/Main/MatlabDataRegression or you could try Python: apmonitor.com/che263/index.php/Main/PythonDataRegression

  • @JackSparrow-yt3qw
    @JackSparrow-yt3qw2 жыл бұрын

    I am trying to do regression non-linear on a data of force-displacement. I would like to ask how to know the equation in advance (as you mostly do know at the start of your videos related to regression) without doing the fit first? I have a data with strain-hardening behavior

  • @apm

    @apm

    2 жыл бұрын

    Coming up with the correct form of the equation is typically based on physics-based principles. Another approach is to use machine learning where the equations are determined by the algorithm: apmonitor.com/pds/ (see Regression section).

  • @Chikka92
    @Chikka925 жыл бұрын

    What's the difference of fmincon and Polyval? Does polyval return same results as of fmincon for a given set of data?

  • @apm

    @apm

    5 жыл бұрын

    fmincon is a general purpose solver while polyval is just for fitting polynomials to data. See apmonitor.com/che263/index.php/Main/MatlabOptimization and apmonitor.com/che263/index.php/Main/MatlabDataRegression

  • @gotravelbuddy
    @gotravelbuddy2 жыл бұрын

    Hi, how about if the function is in complex number form. eg: y (x) = A(x) + B(x)*i . Thanks

  • @apm

    @apm

    2 жыл бұрын

    Does this help? www.mathworks.com/help/optim/ug/complex-numbers-in-optimization-toolbox-solvers.html

  • @mengzhuwang3859
    @mengzhuwang38592 жыл бұрын

    Thank you John, this is an excellent video! Thank you for the tutorial! My problem is that I wrote the same command with you . But the results I got are dependent on the random number I gave to P0 at the beginning, which means that if I input p0=[1,2] and p0=[2,3], I will get a totally different Popt. I don't know even how to describe this problem in Google >

  • @apm

    @apm

    2 жыл бұрын

    Initial guesses are important, especially with less powerful solvers. See the Gekko solution to the same problem here: apmonitor.com/che263/index.php/Main/PythonDataRegression

  • @musafir1068
    @musafir10686 жыл бұрын

    its awesome.video quality is not good.plz makes videos on the fitting of large noisy by using user-defined functions.

  • @apm

    @apm

    6 жыл бұрын

    You may need to wait for the video to buffer for 1080p video resolution. Higher quality video is available but may be limited by your bandwidth. This method should also work with noisy data. See apmonitor.com/che263/index.php/Main/PythonRegressionStatistics for another example with a user-defined function.

  • @zahrahoseini4088
    @zahrahoseini40885 жыл бұрын

    What should we do if we want the sum of the errors?

  • @apm

    @apm

    5 жыл бұрын

    You can compute it with sum((ym-yp).^2) where ym is your vector of measurements and yp is your vector of predicted values.

  • @abdelmalekmezrag2849
    @abdelmalekmezrag28494 жыл бұрын

    Sir thnx for ur tutorial! but I have a problem, Where I want to solve an error regression with an objective function contains a parameter contains three values at the same time, one always remains fixed and for the other two takes a value it depends on tells conditions how I can do that please !

  • @apm

    @apm

    4 жыл бұрын

    Yes, you can do multivariate regression. You can additional parameters to the model.

  • @abdelmalekmezrag2849

    @abdelmalekmezrag2849

    4 жыл бұрын

    @@apm OK thnx, I will try

  • @eduardobustos1887
    @eduardobustos18873 жыл бұрын

    I getting this error: "Error in fmincon (line 859) options = getIpOptions(options,sizes.nVar,mEq,flags.constr,defaultopt,10,0.01)"

  • @apm

    @apm

    3 жыл бұрын

    Check the MathWorks website for that specific option. Here is some help on fmincon: apmonitor.com/che263/index.php/Main/MatlabOptimization

  • @firassami7399
    @firassami73995 жыл бұрын

    Hello sir,it is really very usefull lesson. I am facing trouble and I hope to help me in coding. I want to separate the coeffisions to solve advace problems like below p1=4 p2=.54 p3=-0.1 yp =@(p1,p2,p3) p1+p2./xm +log (xm).*p3 obj=@(p1,p2,p3) sum ((yp (p1,p2,p3)-ym)./ym).^2) p_ottimal =fmincon (pbjective,(p1,p2,p3)) i found error in fmincon can you help me

  • @apm

    @apm

    5 жыл бұрын

    If it's an error that it didn't converge then you may need to give better guess values for the optimizer. If it still isn't solving then a better optimizer such as APM Matlab may be better.

  • @firassami7399

    @firassami7399

    5 жыл бұрын

    @@apm Thank you soo much

Келесі