Linear Regression

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Linear Regression

LucaLuca
hi,
look this pics

https://gyazo.com/1f61457f939308195d72bba5f4266bc5

i need to find linea regression

i use this formula:

A=[4 3 2 0 1 8]
B=[1 2 3 4 5 6]

regress(A,B)

is write :error: regress: y must be a column vector

i don't understand :|

i read example but i don't understand that..

i need to find a series of points that approximate my range A



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Linear Regression

Przemek Klosowski-7
On 12/7/18 12:52 PM, LucaLuca wrote:
regress(A',B') resolves that issue, but your B/A data doesn't look like
your picture, so I am not sure if that's what you need.

By the way, for simple linear regression, you can do polyfit(x,y,1)

>
> i don't understand :|
>
> i read example but i don't understand that..
>
> i need to find a series of points that approximate my range A

Do you mean some sort of linear approximation of A based on fitted data?

polyval(polyfit(x,y,1),x)




Reply | Threaded
Open this post in threaded view
|

Re: Linear Regression

marco atzeri-2
In reply to this post by LucaLuca
Am 07.12.2018 um 18:52 schrieb LucaLuca:

> hi,
> look this pics
>
> https://gyazo.com/1f61457f939308195d72bba5f4266bc5
>
> i need to find linea regression
>
> i use this formula:
>
> A=[4 3 2 0 1 8]
> B=[1 2 3 4 5 6]
>
> regress(A,B)
>
> is write :error: regress: y must be a column vector
>
> i don't understand :|

you give rows, it needs columns

regress(A',B')
ans =  0.75824


>
> i read example but i don't understand that..
>
> i need to find a series of points that approximate my range A
>

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus



Reply | Threaded
Open this post in threaded view
|

Re: Linear Regression

LucaLuca
In reply to this post by Przemek Klosowski-7
hi,
i try this example :

function esercizio_interpolazione()
 
  pkg load statistics
 
  a=[4 5 6 -1 0 4 -2 0 -3]
 
  b=[1 2 3 4 5 6 7 8 9]
 
  yi =polyfit(a',b',1)
 
  hold on
  plot(b',a','b')
 
  plot(yi,'c')
endfunction

look this pics:

https://gyazo.com/521d0d62cb33d334251e374c27fdce92







--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Linear Regression

marco atzeri-2
Am 08.12.2018 um 01:06 schrieb LucaLuca:

> hi,
> i try this example :
>
> function esercizio_interpolazione()
>    
>    pkg load statistics
>    
>    a=[4 5 6 -1 0 4 -2 0 -3]
>    
>    b=[1 2 3 4 5 6 7 8 9]
>    
>    yi =polyfit(a',b',1)

Luca,

you should read the documentation with some attention

  -- P = polyfit (X, Y, N)
  -- [P, S] = polyfit (X, Y, N)
  -- [P, S, MU] = polyfit (X, Y, N)
      Return the coefficients of a polynomial P(X) of degree N that
      minimizes the least-squares-error of the fit to the points '[X,
      Y]'.


You are inverting X and Y


  yi =polyfit(b',a',1)
yi =

   -0.90000   5.94444


>    
>    hold on
>    plot(b',a','b')
>    
>    plot(yi,'c')
> endfunction
>
> look this pics:
>
> https://gyazo.com/521d0d62cb33d334251e374c27fdce92
>

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus



Reply | Threaded
Open this post in threaded view
|

Re: Linear Regression

LucaLuca
This post was updated on .
hi,

i don't understand

if i want to get this line :

https://gyazo.com/942676a11228bc3c610419faa0867bc7


how can i do it? :(


i try to use
https://octave.sourceforge.io/optim/function/LinearRegression.html

but it give me error :" 'LinearRegression' undefined near line 1 column 1 "

--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Linear Regression

marco atzeri-2
Am 08.12.2018 um 10:14 schrieb LucaLuca:

> hi,
>
> i don't understand
>
> if i want to get this line :
>
> https://gyazo.com/942676a11228bc3c610419faa0867bc7
>
>
> how can i do it? :(
>

Luca,
I understand that learning a new language is difficult, but it seems
you need to follow some tutorial for the basis.
Almost all your questions are very elementary.


polyfit provides the coefficients of N grade polinomial
that fit the data.

For grade 1 the polinomial is m*x+c so

  yi =polyfit(b',a',1)
yi =

   -0.90000   5.94444

where yi(1) is "m" and yi(2) is "c"

and the Y of the given line for the same x data will be

y=b*yi(1)+yi(2)
y =

  Columns 1 through 8:

    5.04444   4.14444   3.24444   2.34444   1.44444   0.54444  -0.35556
-1.25556

  Column 9:

   -2.15556

and you can plot the data and the line together with

  plot(b,a,b,y)

I hope that this is enough to clarify you the matter

Regards
Marco

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus



Reply | Threaded
Open this post in threaded view
|

Re: Linear Regression

LucaLuca



thank you very kind for your patience



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html