国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

java回歸中的殘差平方和的均值

2019-11-11 06:57:42
字體:
供稿:網(wǎng)友

以下,是我在寫一個算法時中的一小部分,程序給了一個簡單的算例。

計(jì)算殘差平方和的均值。 以下是殘差平方和公式。 這里寫圖片描述

package sampling.method;import java.util.HashMap;import java.util.Map;import org.apache.commons.math3.linear.Array2DRowRealMatrix;import org.apache.commons.math3.linear.RealMatrix;public class Test { public static void main(String[] args) { Map<Integer,RealMatrix > ymatrix=new HashMap<Integer,RealMatrix >(); double[][] y1={{1,2,3,4}}; RealMatrix y1matrix = new Array2DRowRealMatrix(y1); double[][] y2={{2,3,3,5,7}}; RealMatrix y2matrix = new Array2DRowRealMatrix(y2); //這里的1和2分別表示類別 ymatrix.put(1, y1matrix); ymatrix.put(2, y2matrix); // Map<Integer,RealMatrix > xMatrixList=new HashMap<Integer,RealMatrix >(); double[][] x1={{1,2},{3,4},{2,4},{2,4}}; double[][] x2={{1,2},{3,4},{0,0},{5,4},{2,6}}; RealMatrix x1mat = new Array2DRowRealMatrix(x1); RealMatrix x2mat = new Array2DRowRealMatrix(x2); xMatrixList.put(1, x1mat); xMatrixList.put(2, x2mat); // Map<Integer,RealMatrix > wMatrixList=new HashMap<Integer,RealMatrix >(); double[][] w1={{1,2}}; double[][] w2={{2,3}}; RealMatrix w1mat = new Array2DRowRealMatrix(w1); RealMatrix w2mat = new Array2DRowRealMatrix(w2); wMatrixList.put(1, w1mat); wMatrixList.put(2, w2mat); double sum=0.0; int dimension=0; for( int itemnumber : ymatrix.keySet() ){ RealMatrix yscore=ymatrix.get(itemnumber) ; dimension+=yscore.getColumnDimension(); RealMatrix wxscore=wMatrixList.get(itemnumber).multiply(xMatrixList.get(itemnumber).transpose()) ; RealMatrix ysbuwxscore =yscore.add(wxscore.scalarMultiply(-1.0)); System.out.PRintln(yscore.add(wxscore.scalarMultiply(-1.0))); System.out.println(ysbuwxscore.multiply(ysbuwxscore.transpose())); sum+=sumarray(ysbuwxscore.multiply(ysbuwxscore.transpose())); } System.out.println("殘差平方和均值為:"+sum/dimension); } private static double sumarray(RealMatrix a){ double[][] arr=a.getData(); double sum = 0.0; for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { sum += arr[i][j]; } } return sum; }}

這里寫圖片描述


上一篇:Java習(xí)題集

下一篇:java反射機(jī)制

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 永德县| 阿拉善右旗| 修文县| 陈巴尔虎旗| 鄢陵县| 双鸭山市| 兴国县| 类乌齐县| 诸城市| 油尖旺区| 津市市| 宁夏| 波密县| 孝义市| 万载县| 郓城县| 连平县| 岳阳市| 黔江区| 上犹县| 瓦房店市| 买车| 丽水市| 饶平县| 昌宁县| 开鲁县| 含山县| 贵州省| 兴义市| 金堂县| 吕梁市| 龙江县| 井研县| 景洪市| 雅江县| 三亚市| 阳原县| 诏安县| 六枝特区| 罗山县| 陕西省|