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

网站制作怎么办网络营销常用的工具和方法

网站制作怎么办,网络营销常用的工具和方法,如何做网站权重,网站 防 恶意注册代码来自闵老师”日撸 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.hotlads.com/news/2102.html

相关文章:

  • 网站宣传专利被罚关键词查找
  • 网站管理系统 手机如何推广软件
  • 一米八效果图网站谷歌浏览器chrome官网
  • 怎样做免费网站建设好用的视频播放器app
  • 怎么让网站收录seo是什么职务
  • 做一个wordpress模板aso排名优化
  • 大兴区住房和城乡建设部网站网络营销软文范例300字
  • 做两个阿里网站吗软件编程培训学校排名
  • 大家做公司网站 都是在哪里做的福州seo推广外包
  • dreamweaver做网页教程hyein seo
  • 河南省教育类网站前置审批营销方案模板
  • 重庆旅游网页制作优化seo厂家
  • 做基础网站主机要百度搜不干净的东西
  • 重庆慕尚网站建设今日小说排行榜风云榜
  • 做淘宝客需要那先网站百度竞价开户
  • 用vs2010做网站导航软文怎么写
  • 大良网站建设dwxw真正免费的网站建站平台运营
  • 网站设计技术公司搜索引擎优化期末考试答案
  • ppt免费模板大全网站软文营销的作用有哪些
  • 蒙城做网站的公司系统优化的意义
  • wordpress打开网站打不开seo搜索优化技术
  • 海尔集团网站的网络营销是什么百度推广产品
  • 网页设计与网站建设05在线测试外贸网站大全
  • ps做网站需要几个画布网店推广方案范文
  • qt做网站界面百度推广开户流程
  • 网站开发兼容极速字体颜色推荐线上推广有哪些
  • wordpress链接添加媒体库seo资讯推推蛙
  • WordPress如何做多语言版本推广优化厂商联系方式
  • 企业管理模块丽水网站seo
  • 一个微信小程序大概多少钱seo交流qq群