Linear regression refers to the attempt to learn a linear model to predict real-value output markers as accurately as possible.
Least squares: The method of solving the model based on the minimization of mean square error.
By becoming the least squares method (perhaps not the most simplified, to improve the programming ability)
/** This is a linear regression problem with least squares*/classlinearregression {DoubleA; Doubleb; intN; PublicLinearregression (Double[] Arrx,Double[] arry) { //TODO auto-generated Constructor stub DoubleT1 = 0; DoubleT2 = 0; DoubleT3 = 0; DoubleT4 = 0; N=arrx.length; for(inti = 0; I < n; i++) {T1= Arrx[i] +T1; T2= Arry[i] +T2; T3= arry[i] * Arrx[i] +T3; T4= arrx[i] * Arrx[i] +T4; } A= (T3*N-T1 * T2)/(T4*N-T1 *t1); b= (T2-A * T1)/N; System.out.println (a); System.out.println (b); } voidPrint () {System.out.println ("The result of using linear least squares is y=" + A + "*x+" +b); } voidPredictDoublenum) { Doubleresult = num * A +b; System.out.println ("The result of using least squares is:" +result); }} Public classRegressdemo { Public Static voidMain (string[] args) {DoubleArrx[] =New Double[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; DoubleArry[] =New Double[] {23, 44, 32, 56, 33, 34, 55, 65, 45, 55 }; linearregression LR=Newlinearregression (Arrx, Arry); Lr. Print (); Lr.predict (1.0); }}
Least squares method for regression of algorithm------