octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Model object as output after fitting the linear model


From: Markus
Subject: Re: Model object as output after fitting the linear model
Date: Mon, 22 Sep 2014 21:16:44 +0200
User-agent: Roundcube Webmail/1.0.0

Am 2014-09-22 13:53, schrieb Krishnaprasad:
Hallo all,

I am using Octave 3.8.0 to build a linear model that has several input
features and one output feature. I am using this model in order to predict the output for the given set of input features. When I searched on the web
for statistical packages, I found the following functions: polyfit and
regress. But none of these functions returns me a model object which I can
use it for prediction.

Can I kindly know from the forum is there a function in octave that returns
me a model object for linear regression?


Something like that?


function f = fitml(y)

        B = polyfit (1:length(y),y,1);
        f = @(x) (B(1))*x + B(2);

end



octave:1> y = [0 1 3 2 4 3 6 5 6 7];
octave:2> model1 = fitml(y)
model1 =

@(x) B (1) * x + B (2)

octave:3> model1(192)
ans =     138.206060606061
octave:4> polyfit (1:length(y),y,1)
ans =

     0.721212121212121    -0.266666666666668

octave:5> ans(1)*192+ans(2)
ans =     138.206060606061


And if you need informations about m and b

function f = fitml(y)

        B = polyfit (1:length(y),y,1);
        f.mdl = @(x) B(1)*x + B(2);
        f.m = rats(B(1)); % this is a char!
        f.b = rats(B(2)); % this is a char!

end


use f = fitml(y); and f.mdl(192) or f.m e.g.

But maybe I don't understand what you're looking for.





Best regards,
Krishnaprasad



--
View this message in context:
http://octave.1599824.n4.nabble.com/Model-object-as-output-after-fitting-the-linear-model-tp4666621.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.

--
https://github.com/markuman
Jabber: address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]