当前位置: 首页 > news >正文

查询建设规范的网站h5页面设计软件

查询建设规范的网站,h5页面设计软件,天津专业做网站的公司,网络ip查询网站代码来自闵老师”日撸 Java 三百行(61-70天) 日撸 Java 三百行(61-70天,决策树与集成学习)_闵帆的博客-CSDN博客 学习过程中理解算法参考了:(十三)通俗易懂理解——Adaboost算法原…

 代码来自闵老师”日撸 Java 三百行(61-70天)

日撸 Java 三百行(61-70天,决策树与集成学习)_闵帆的博客-CSDN博客

学习过程中理解算法参考了:(十三)通俗易懂理解——Adaboost算法原理 - 知乎 (zhihu.com)

 今天的代码的核心是方法adjustWeights(boolean[] paraCorrectArray, double paraAlpha)。分类正确的实例,权重调整为原值除以Math.exp(paraAlpha);分类错误的调整为原值乘以Math.exp(paraAlpha)。

测试方法里,之所以for循环到tempCorrectArray长度的一半,仅仅是为了测试。相当于设置弱分类器分类正确了一半。

package machinelearning.adaboosting;import java.io.FileReader;
import java.util.Arrays;import weka.core.Instances;/*** Weighted instances.<br>* * @author WX873**/
public class WeightedInstances extends Instances{/*** Just the requirement of some classes, any number is ok.*/private static final long serialVersionUID = 11087456L;/*** Weights*/private double[] weights;/*** *************************************************** The first constructor.* * @param paraFileReader   The given reader to read data from file.* @throws Exception* ***************************************************/public WeightedInstances(FileReader paraFileReader) throws Exception{// TODO Auto-generated constructor stubsuper(paraFileReader);setClassIndex(numAttributes() - 1);// Initialize weightsweights = new double[numInstances()];double tempAverage = 1.0/numInstances();for (int i = 0; i < weights.length; i++) {weights[i] = tempAverage;}//of for iSystem.out.println("Instances weights are: " + Arrays.toString(weights));}//of the first constructor/*** *********************************************************** The second constructor.* * @param paraInstances* ***********************************************************/public WeightedInstances(Instances paraInstances) {// TODO Auto-generated constructor stubsuper(paraInstances);setClassIndex(numAttributes() - 1);//Initialize weightsweights = new double[numInstances()];double tempAverage = 1.0/numInstances();for (int i = 0; i < weights.length; i++) {weights[i] = tempAverage;}//of for iSystem.out.println("Instances weights are: " + Arrays.toString(weights));}//of the second constructor/*** **************************************************** Getter.* * @param paraIndex   The given index.* @return    The weight of the given index.* ****************************************************/public double getWeight(int paraIndex) {return weights[paraIndex];}//of getWeight/*** ****************************************************** Adjust the weights.* * @param paraCorrectArray  Indicate which instances have been correctly classified.* @param paraAlpha   The weight of the last classifier.* ******************************************************/public void adjustWeights(boolean[] paraCorrectArray, double paraAlpha) {//Step 1. Calculate alpha.double tempIncrease = Math.exp(paraAlpha);//Step 2. Adjust.double tempWeightsSum = 0;  // For normalization.for (int i = 0; i < weights.length; i++) {if (paraCorrectArray[i]) {weights[i] /= tempIncrease;} else {weights[i] *= tempIncrease;}//of iftempWeightsSum += weights[i];}//of for i// Step 3. Normalize.for (int i = 0; i < weights.length; i++) {weights[i] /= tempWeightsSum;}//of for iSystem.out.println("After adjusting, instances weights are: " + Arrays.toString(weights));}//of adjustWeights/*** ********************************************** Test the method.* **********************************************/public void adjustWeightsTest() {boolean[] tempCorrectArray = new boolean[numInstances()];for (int i = 0; i < tempCorrectArray.length / 2; i++) {    //仅仅是测试adjustWeights()方法,因为还没有分类器,设置分类正确了一半tempCorrectArray[i] = true;}//of for idouble tempWeightedError = 0.3;adjustWeights(tempCorrectArray, tempWeightedError);     //仅仅是测试adjustWeights()方法,因为还没有分类器System.out.println("After adjusting");System.out.println(toString());}//of adjustWeightsTest/*** ********************************************************* For display.* *********************************************************/public String toString() {String resultString = "I am a weighted Instances object.\r\n" + "I have " + numInstances() + " instances and "+ (numAttributes() - 1) + " conditional attributes.\r\n" + "My weights are: " + Arrays.toString(weights)+ "\r\n" + "My data are: \r\n" + super.toString();return resultString;}//of toString/*** ************************************************************ The entrance of the program.* * @param args* ************************************************************/public static void main(String args[]) {WeightedInstances tempWeightedInstances = null;String tempFilename = "E:/Datasets/UCIdatasets/其他数据集/iris.arff";try {FileReader tempFileReader = new FileReader(tempFilename);tempWeightedInstances = new WeightedInstances(tempFileReader);tempFileReader.close();} catch (Exception exception1) {// TODO: handle exceptionSystem.out.println("Cannot read the file: " + tempFilename + "\r\n" + exception1);System.exit(0);}//of trySystem.out.println(tempWeightedInstances.toString());tempWeightedInstances.adjustWeightsTest();}//of main}//of WeightedInstances

http://www.yayakq.cn/news/118296/

相关文章:

  • 淘宝网站建设 推广 上海网站怎样做 文件签收
  • 做民宿最大的网站花都网站开发公司
  • 重庆哪里有做淘宝网站推广的网站选项按钮
  • 建设公司网站需要注意什么宁波网站公司哪家好
  • 企业网站不付服务费应该怎么做贵阳奇点未来网站建设
  • 网站怎么建设模块中山外包网站设计
  • 浙江建设工程合同备案网站乡村建设的网站
  • 巧家县城乡建设局网站邹平网站建设
  • 如何攻克网站wordpress服务本地
  • 个体户做盈利网站东圃手机网站制作费用
  • 肇庆网站搜索排名重庆广告公司前十名
  • 一个公司可以做多少个网站市北区大型网站建设
  • 电影网站备案域名网站教程
  • 建站网站软件8wordpress怎么加入引导页面
  • 沈阳模板建站方案wordpress the7 官网
  • 国内用wordpress建设seo排名优化公司
  • 站外引流推广渠道平面广告设计价格
  • 旅游网站建设与规划服装网站建设前期规划方案
  • 做卖车的网站有哪些wordpress 概要
  • 东莞网站平台后缀中国十大搜索引擎排名最新
  • 企业网站建设全包yahoo怎么提交网站
  • 做网站的的报价装潢设计图片三室一厅
  • 龙岗坪地网站建设网站建设需要哪些流程
  • 做垂直网站外贸 网站 源码
  • 大连seo网站管理wordpress套模板教程
  • iss服务器网站建设自己电脑做服务器上传网站 需要备案吗
  • 做外贸网站卖什么好处浙江省建设工程质量安全协会网站
  • 昆明中国建设银行网站石家庄的网站的公司
  • 网站客户需求分析五大常用办公软件
  • 旅游电子商务网站设计建设厅证书查询