viernes, 22 de febrero de 2019

Linear regression on JS (works on chrome browser console)

Para que no se les canse el dedo picándole a la calculadora, quick and dirty JS code for linear regression para uso en su siempre amiga consola de Javascript (command,alt,J) 

function mult (a){return a[0]*a[1]}

function x(a){return a[0]}

function y(a){return a[1]}

function xsquare(a){return a[0]*a[0]}


function sumArray(A, func){ sum =0 ;for (i=0;i

function linearw1(data) { return (data.length * sumArray(data,mult) - sumArray(data,x)*sumArray(data,y))/ (data.length * sumArray(data,xsquare) - (sumArray(data,x)* sumArray(data,x)) ) }

function linearw0(data) {return (1/data.length) * sumArray(data,y) - (linearw1(data) / data.length )*sumArray(data,x)}

data = [[2,2],[4,5],[6,5],[8,8]]

linearw1(data)

linearw0(data)


Juan Martín Barrios Vargas - comentó 2011-10-27 06:49:48-0700
Como lo hago yo en R:
data <- 4="" 5="" 6="" 8="" br="" c="" cbind="">data <- as.data.frame="" br="" data="">lm(V1~V2, data)
si quieres más información estadística se puede hacer
linear.info <- br="" data="" lm="">summary(linear.info)

Silence broken by repetition

So G+ is shutting down so I did the takeout thing and start browsing through my post (mostly throwaways) but every once in a while I will have things that are still worth preserving so I will add them here if I find something worth publishing