最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Spark實(shí)現(xiàn)隨機(jī)森林代碼

 更新時(shí)間:2019年08月10日 11:50:09   作者:KevinYunhe  
這篇文章主要為大家詳細(xì)介紹了基于Spark實(shí)現(xiàn)隨機(jī)森林代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了基于Spark實(shí)現(xiàn)隨機(jī)森林的具體代碼,供大家參考,具體內(nèi)容如下

public class RandomForestClassficationTest extends TestCase implements Serializable
{
 
  /**
  * 
  */
  private static final long serialVersionUID = 7802523720751354318L;
  
  class PredictResult implements Serializable{
    /**
    * 
    */
    private static final long serialVersionUID = -168308887976477219L;
    double label;
    double prediction;
    
    public PredictResult(double label,double prediction){
    this.label = label;
    this.prediction = prediction;
    }
    
    @Override
    public String toString(){
      return this.label + " : " + this.prediction ;
    }
  }
  
  
  public void test_randomForest() throws JAXBException{
  
    SparkConf sparkConf = new SparkConf();
    sparkConf.setAppName("RandomForest");
    sparkConf.setMaster("local");
    
    SparkContext sc = new SparkContext(sparkConf);
    String dataPath = RandomForestClassficationTest.class.getResource("/").getPath() + "/sample_libsvm_data.txt";
    
    RDD dataSet = MLUtils.loadLibSVMFile(sc, dataPath);
    RDD[] rddList = dataSet.randomSplit(new double[]{0.7,0.3},1);
    
    RDD trainingData = rddList[0];
    RDD testData = rddList[1];
    
    ClassTag labelPointClassTag = trainingData.elementClassTag();
    
    JavaRDD trainingJavaData = new JavaRDD(trainingData,labelPointClassTag);
    
    int numClasses = 2;
    Map categoricalFeatureInfos = new HashMap();
    int numTrees = 3;
    String featureSubsetStrategy = "auto";
    String impurity = "gini";
    int maxDepth = 4;
    int maxBins = 32;
    
    /**
    * 1 numClasses分類個(gè)數(shù)為2
    * 2 numTrees 表示的是隨機(jī)森林中樹的個(gè)數(shù)
    * 3 featureSubsetStrategy
    * 4 
    */
    final RandomForestModel model = RandomForest.trainClassifier(trainingJavaData,
    numClasses,
    categoricalFeatureInfos,
    numTrees,
    featureSubsetStrategy,
    impurity,
    maxDepth,
    maxBins,
    1);
 
    JavaRDD testJavaData = new JavaRDD(testData,testData.elementClassTag());
    
    JavaRDD predictRddResult = testJavaData.map(new Function(){
 
 
    /**
    * 
    */
    private static final long serialVersionUID = 1L;
    
    
    public PredictResult call(LabeledPoint point) throws Exception {
      // TODO Auto-generated method stub
      double pointLabel = point.label();
      double prediction = model.predict(point.features());
      PredictResult result = new PredictResult(pointLabel,prediction);
      return result;
    }
    
    });
 
    List predictResultList = predictRddResult.collect();
    for(PredictResult result:predictResultList){
      System.out.println(result.toString());
    }
    
      System.out.println(model.toDebugString());
    }
}

得到的隨機(jī)森林的展示結(jié)果如下:

TreeEnsembleModel classifier with 3 trees
 
 
Tree 0:
If (feature 435 <= 0.0)
If (feature 516 <= 0.0)
Predict: 0.0
Else (feature 516 > 0.0)
Predict: 1.0
Else (feature 435 > 0.0)
Predict: 1.0
Tree 1:
If (feature 512 <= 0.0)
Predict: 1.0
Else (feature 512 > 0.0)
Predict: 0.0
Tree 2:
If (feature 377 <= 1.0)
Predict: 0.0
Else (feature 377 > 1.0)
If (feature 455 <= 0.0)
Predict: 1.0
Else (feature 455 > 0.0)
Predict: 0.0

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Javassist用法詳解

    Javassist用法詳解

    這篇文章主要介紹了Javassist用法的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用Java,感興趣的朋友可以了解下
    2021-02-02
  • Java中File文件操作類的基礎(chǔ)用法

    Java中File文件操作類的基礎(chǔ)用法

    這篇文章主要給大家介紹了關(guān)于Java中File文件操作類基礎(chǔ)用法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用File類具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • 30分鐘入門Java8之默認(rèn)方法和靜態(tài)接口方法學(xué)習(xí)

    30分鐘入門Java8之默認(rèn)方法和靜態(tài)接口方法學(xué)習(xí)

    這篇文章主要介紹了30分鐘入門Java8之默認(rèn)方法和靜態(tài)接口方法學(xué)習(xí),詳細(xì)介紹了默認(rèn)方法和接口,有興趣的可以了解一下。
    2017-04-04
  • Java工廠模式定義與用法實(shí)例分析

    Java工廠模式定義與用法實(shí)例分析

    這篇文章主要介紹了Java工廠模式定義與用法,結(jié)合具體實(shí)例形式分析了java工廠模式定義、使用相關(guān)操作技巧,并總結(jié)了類圖原理,需要的朋友可以參考下
    2019-07-07
  • Spring Cloud Gateway的配置與使用教程

    Spring Cloud Gateway的配置與使用教程

    這篇文章主要介紹了Spring Cloud Gateway的配置與使用,通過本文的介紹,我們了解了Spring Cloud Gateway的核心概念和基本配置,需要的朋友可以參考下
    2023-06-06
  • SpringBoot 配置文件中配置的中文,程序讀取出來是亂碼的解決

    SpringBoot 配置文件中配置的中文,程序讀取出來是亂碼的解決

    這篇文章主要介紹了SpringBoot 配置文件中配置的中文,程序讀取出來是亂碼的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • Java 實(shí)現(xiàn)線程池任務(wù)編排的示例代碼

    Java 實(shí)現(xiàn)線程池任務(wù)編排的示例代碼

    任務(wù)編排是將多個(gè)任務(wù)按照特定的依賴關(guān)系和執(zhí)行順序進(jìn)行組織和管理的過程,以確保任務(wù)能按預(yù)定邏輯順序高效執(zhí)行,本文就來介紹一下Java 實(shí)現(xiàn)線程池任務(wù)編排的示例代碼,感興趣的可以了解一下
    2024-10-10
  • Java程序進(jìn)程起來了但是不打印日志的原因分析

    Java程序進(jìn)程起來了但是不打印日志的原因分析

    這篇文章主要介紹了Java程序進(jìn)程起來了但是不打印日志的原因分析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-04-04
  • springsecurity輕松實(shí)現(xiàn)角色權(quán)限的示例代碼

    springsecurity輕松實(shí)現(xiàn)角色權(quán)限的示例代碼

    這篇文章主要介紹了springsecurity輕松實(shí)現(xiàn)角色權(quán)限的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • 解決java junit單元測(cè)試@Test報(bào)錯(cuò)的問題

    解決java junit單元測(cè)試@Test報(bào)錯(cuò)的問題

    今天小編就為大家分享一篇解決java junit單元測(cè)試@Test報(bào)錯(cuò)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-11-11

最新評(píng)論

滦平县| 彰化县| 新营市| 杭锦后旗| 定结县| 休宁县| 土默特右旗| 海丰县| 巴林左旗| 抚顺市| 肥城市| 清镇市| 惠州市| 潼南县| 五华县| 新兴县| 田阳县| 澄城县| 民乐县| 汕尾市| 永仁县| 封丘县| 任丘市| 牟定县| 长岭县| 绥江县| 枣阳市| 精河县| 睢宁县| 达孜县| 昌图县| 康定县| 旬邑县| 遵化市| 溧水县| 凌云县| 隆安县| 新龙县| 绥阳县| 达孜县| 平凉市|