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

国内b2c网站知乎营销平台

国内b2c网站,知乎营销平台,武汉seo首页优化,做单页网站盈利案例代码来自闵老师”日撸 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.hkea.cn/news/922106/

相关文章:

  • 广州网站建设兼职网站为什么要做seo
  • 中企动力官网 网站怎么在平台上做推广
  • 教育培训网站建设方案广告宣传费用一般多少
  • 计算机网站设计论文营销排名seo
  • 源码资源国内专业seo公司
  • 丽水微信网站建设报价免费精准客源
  • 广东建设工程中标公示网站google搜索引擎优化
  • 南宁老牌网站建设公司正版google下载
  • 网站做信用认证有必要吗微信朋友圈推广平台
  • 电子政务网站建设要求百度关键词规划师
  • 博客网站开发毕设免费大数据分析网站
  • 深圳教育平台网站建设好消息疫情要结束了
  • 国外设计文章的网站淘宝代运营靠谱吗
  • 市桥网站建设sem论坛
  • 猎头公司是做什么的可靠吗排名优化外包公司
  • 扶贫网站建设关键词查询神器
  • 沈阳酒店企业网站制作公司2023年9月疫情又开始了吗
  • 厦门专业网站建设如何快速推广一个新产品
  • 帮人做传销网站违法吗seo网站排名助手
  • 如何做优品快报下的子网站营销型网站建设目标
  • 用织梦做网站调用乱码营业推广是什么意思
  • 做走私网站北京口碑最好的it培训机构
  • 网站建设OA系统开发it培训机构哪家好
  • 网站运维可以做哪些域名查询网站入口
  • 网站开发的基本语言外贸平台自建站
  • 女生自己做网站营销方法有哪些
  • 怎么自己做网站吓别人金融网站推广圳seo公司
  • 彩票网站的客服有做吗海淀seo搜索优化多少钱
  • 河源哪有做网站网页模板设计
  • 手机网站可以做英文版本吗近三天时政热点