亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Spark隨機(jī)森林實(shí)現(xiàn)票房預(yù)測(cè)

 更新時(shí)間:2019年08月10日 12:43:01   作者:Quincy1994  
這篇文章主要為大家詳細(xì)介紹了Spark隨機(jī)森林實(shí)現(xiàn)票房預(yù)測(cè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

前言

最近一段時(shí)間都在處理電影領(lǐng)域的數(shù)據(jù), 而電影票房預(yù)測(cè)是電影領(lǐng)域數(shù)據(jù)建模中的一個(gè)重要模塊, 所以我們針對(duì)電影數(shù)據(jù)做了票房預(yù)測(cè)建模.

前期工作

一開(kāi)始的做法是將這個(gè)問(wèn)題看待成回歸的問(wèn)題, 采用GBDT回歸樹去做. 訓(xùn)練了不同殘差的回歸樹, 然后做集成學(xué)習(xí). 考慮的影響因子分別有電影的類型, 豆瓣評(píng)分, 導(dǎo)演的 影響力, 演員的影響力, 電影的出品公司. 不過(guò)預(yù)測(cè)的結(jié)果并不是那么理想, 準(zhǔn)確率為真實(shí)值的0.3+/-區(qū)間情況下的80%, 且波動(dòng)性較大, 不容易解析.

后期的改進(jìn)

總結(jié)之前的失敗經(jīng)驗(yàn), 主要?dú)w納了以下幾點(diǎn):

1.影響因子不夠多, 難以建模
2.票房成績(jī)的區(qū)間較大(一百萬(wàn)到10億不等),分布不均勻, 大多數(shù)集中與億級(jí), 所以不適合采用回歸方法解決.
3.數(shù)據(jù)樣本量比較少, 不均勻, 預(yù)測(cè)百萬(wàn)級(jí)的電影較多, 影響預(yù)測(cè)結(jié)果

后期, 我們重新規(guī)范了數(shù)據(jù)的輸入格式, 即影響因子, 具體如下:

第一行: 電影名字
第二行: 電影票房(也就是用于預(yù)測(cè)的, 以萬(wàn)為單位)
第三行: 電影類型
第四行: 片長(zhǎng)(以分鐘為單位)
第五行:上映時(shí)間(按月份)
第六行: 制式( 一般分為2D, 3D, IMAX)
第七行: 制作國(guó)家
第八行: 導(dǎo)演影響 (以導(dǎo)演的平均票房成績(jī)?yōu)楹饬? 以萬(wàn)為單位 )
第九行: 演員影響 ( 以所有演員的平均票房成績(jī)?yōu)楹饬? 以萬(wàn)為單位 )
第十行:制作公司影響 ( 以所有制作公司的平均票房成績(jī)?yōu)楹饬? 以萬(wàn)為單位 )
第十一行: 發(fā)行公式影響 ( 以所有制作公司的平均票房成績(jī)?yōu)楹饬?以萬(wàn)為單位 )

收集了05-17年的來(lái)自中國(guó),日本,美國(guó),英國(guó)的電影, 共1058部電影. 由于處理成為分類問(wèn)題, 故按將電影票房分為以下等級(jí):


在構(gòu)建模型之前, 先將數(shù)據(jù)處理成libsvm格式文件, 然后采用隨機(jī)森林模型訓(xùn)練.

隨機(jī)森林由許多的決策樹組成, 因?yàn)檫@些決策樹的形成采用隨機(jī)的策略, 每個(gè)決策樹都隨機(jī)生成, 相互之間獨(dú)立.模型最后輸出的類別是由每個(gè)樹輸出的類別的眾數(shù)而定.在構(gòu)建每個(gè)決策樹的時(shí)候采用的策略是信息熵, 決策樹為多元分類決策樹.隨機(jī)森林的流程圖如下圖所示:

隨機(jī)森林是采用spark-mllib提供的random forest, 由于超過(guò)10億的電影的數(shù)據(jù)相對(duì)比較少, 為了平衡各數(shù)據(jù)的分布, 采用了過(guò)分抽樣的方法, 訓(xùn)練模型的代碼如下:

public void predict() throws IOException{
  SparkConf conf = new SparkConf().setAppName("SVM").setMaster("local");
  conf.set("spark.testing.memory", "2147480000");
  SparkContext sc = new SparkContext(conf);
  SQLContext sqlContext = new SQLContext(sc);


  // Load and parse the data file, converting it to a DataFrame.
  DataFrame trainData = sqlContext.read().format("libsvm").load(this.trainFile);
  DataFrame testData = sqlContext.read().format("libsvm").load(this.testFile);

  // Index labels, adding metadata to the label column.
  // Fit on whole dataset to include all labels in index.
  StringIndexerModel labelIndexer = new StringIndexer()
   .setInputCol("label")
   .setOutputCol("indexedLabel")
   .fit(trainData);
  // Automatically identify categorical features, and index them.
  // Set maxCategories so features with > 4 distinct values are treated as continuous.
  VectorIndexerModel featureIndexer = new VectorIndexer()
   .setInputCol("features")
   .setOutputCol("indexedFeatures")
   .setMaxCategories(4)
   .fit(trainData);

  // Split the data into training and test sets (30% held out for testing)
//  DataFrame[] splits = trainData.randomSplit(new double[] {0.9, 0.1});
//  trainData = splits[0];
//  testData = splits[1];

  // Train a RandomForest model.
  RandomForestClassifier rf = new RandomForestClassifier()
   .setLabelCol("indexedLabel")
   .setFeaturesCol("indexedFeatures")
   .setNumTrees(20);

  // Convert indexed labels back to original labels.
  IndexToString labelConverter = new IndexToString()
   .setInputCol("prediction")
   .setOutputCol("predictedLabel")
   .setLabels(labelIndexer.labels());

  // Chain indexers and forest in a Pipeline
  Pipeline pipeline = new Pipeline()
   .setStages(new PipelineStage[] {labelIndexer, featureIndexer, rf, labelConverter});

  // Train model. This also runs the indexers.
  PipelineModel model = pipeline.fit(trainData);

  // Make predictions.
  DataFrame predictions = model.transform(testData);

  // Select example rows to display.
  predictions.select("predictedLabel", "label", "features").show(200);

  // Select (prediction, true label) and compute test error
  MulticlassClassificationEvaluator evaluator = new MulticlassClassificationEvaluator()
   .setLabelCol("indexedLabel")
   .setPredictionCol("prediction")
   .setMetricName("precision");
  double accuracy = evaluator.evaluate(predictions);
  System.out.println("Test Error = " + (1.0 - accuracy));

  RandomForestClassificationModel rfModel = (RandomForestClassificationModel)(model.stages()[2]);
//  System.out.println("Learned classification forest model:\n" + rfModel.toDebugString());

  DataFrame resultDF = predictions.select("predictedLabel");
  JavaRDD<Row> resultRow = resultDF.toJavaRDD();
  JavaRDD<String> result = resultRow.map(new Result());
  this.resultList = result.collect();
  for(String one: resultList){
   System.out.println(one);
  }
 }

下面為其中一個(gè)的決策樹情況:

Tree 16 (weight 1.0):
 If (feature 10 in {0.0})
  If (feature 48 <= 110.0)
  If (feature 86 <= 13698.87)
  If (feature 21 in {0.0})
  If (feature 54 in {0.0})
   Predict: 0.0
  Else (feature 54 not in {0.0})
   Predict: 1.0
  Else (feature 21 not in {0.0})
  Predict: 0.0
  Else (feature 86 > 13698.87)
  If (feature 21 in {0.0})
  If (feature 85 <= 39646.9)
   Predict: 2.0
  Else (feature 85 > 39646.9)
   Predict: 3.0
  Else (feature 21 not in {0.0})
  Predict: 3.0
  Else (feature 48 > 110.0)
  If (feature 85 <= 15003.3)
  If (feature 9 in {0.0})
  If (feature 54 in {0.0})
   Predict: 0.0
  Else (feature 54 not in {0.0})
   Predict: 2.0
  Else (feature 9 not in {0.0})
  Predict: 2.0
  Else (feature 85 > 15003.3)
  If (feature 65 in {0.0})
  If (feature 85 <= 66065.0)
   Predict: 3.0
  Else (feature 85 > 66065.0)
   Predict: 2.0
  Else (feature 65 not in {0.0})
  Predict: 3.0
 Else (feature 10 not in {0.0})
  If (feature 51 in {0.0})
  If (feature 85 <= 6958.4)
  If (feature 11 in {0.0})
  If (feature 50 <= 1.0)
   Predict: 1.0
  Else (feature 50 > 1.0)
   Predict: 0.0
  Else (feature 11 not in {0.0})
  Predict: 0.0
  Else (feature 85 > 6958.4)
  If (feature 5 in {0.0})
  If (feature 4 in {0.0})
   Predict: 3.0
  Else (feature 4 not in {0.0})
   Predict: 1.0
  Else (feature 5 not in {0.0})
  Predict: 2.0
  Else (feature 51 not in {0.0})
  If (feature 48 <= 148.0)
  If (feature 0 in {0.0})
  If (feature 6 in {0.0})
   Predict: 2.0
  Else (feature 6 not in {0.0})
   Predict: 0.0
  Else (feature 0 not in {0.0})
  If (feature 50 <= 4.0)
   Predict: 2.0
  Else (feature 50 > 4.0)
   Predict: 3.0
  Else (feature 48 > 148.0)
  If (feature 9 in {0.0})
  If (feature 49 <= 3.0)
   Predict: 2.0
  Else (feature 49 > 3.0)
   Predict: 0.0
  Else (feature 9 not in {0.0})
  If (feature 36 in {0.0})
   Predict: 3.0
  Else (feature 36 not in {0.0})
   Predict: 2.0

后記

該模型預(yù)測(cè)的平均準(zhǔn)確率為80%, 但相對(duì)之前的做法規(guī)范了很多, 對(duì)結(jié)果的解析也更加的合理, 不過(guò)如何增強(qiáng)預(yù)測(cè)的效果, 可以考慮更多的因子, 形如:電影是否有前續(xù);電影網(wǎng)站的口碑指數(shù);預(yù)告片的播放量;相關(guān)微博的閱讀數(shù);百度指數(shù)等;

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

相關(guān)文章

  • 深入解析Apache Kafka實(shí)時(shí)流處理平臺(tái)

    深入解析Apache Kafka實(shí)時(shí)流處理平臺(tái)

    這篇文章主要為大家介紹了Apache Kafka實(shí)時(shí)流處理平臺(tái)深入解析,從基本概念到實(shí)戰(zhàn)操作詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • mybatis快速上手并運(yùn)行程序

    mybatis快速上手并運(yùn)行程序

    MyBatis 是一款優(yōu)秀的持久層框架,它支持自定義 SQL、存儲(chǔ)過(guò)程以及高級(jí)映射。MyBatis 免除了幾乎所有的 JDBC 代碼以及設(shè)置參數(shù)和獲取結(jié)果集的工作。MyBatis 可以通過(guò)簡(jiǎn)單的 XML 或注解來(lái)配置和映射原始類型、接口和 Java POJO為數(shù)據(jù)庫(kù)中的記錄
    2022-01-01
  • 在Spring Boot中使用swagger-bootstrap-ui的方法

    在Spring Boot中使用swagger-bootstrap-ui的方法

    這篇文章主要介紹了在Spring Boot中使用swagger-bootstrap-ui的方法,需要的朋友可以參考下
    2018-01-01
  • idea導(dǎo)入springboot項(xiàng)目沒(méi)有maven的解決

    idea導(dǎo)入springboot項(xiàng)目沒(méi)有maven的解決

    這篇文章主要介紹了idea導(dǎo)入springboot項(xiàng)目沒(méi)有maven的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • springboot整合freemarker詳解

    springboot整合freemarker詳解

    本篇文章主要介紹了springboot整合freemarker詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-05-05
  • Java多態(tài)(動(dòng)力節(jié)點(diǎn)Java學(xué)院整理)

    Java多態(tài)(動(dòng)力節(jié)點(diǎn)Java學(xué)院整理)

    多態(tài)是指允許不同類的對(duì)象對(duì)同一消息做出響應(yīng)。即同一消息可以根據(jù)發(fā)送對(duì)象的不同而采用多種不同的行為方式。接下來(lái)通過(guò)本文給大家介紹java多態(tài)相關(guān)知識(shí),感興趣的朋友一起學(xué)習(xí)吧
    2017-04-04
  • MyBatis?的?XML?配置文件和緩存使用步驟

    MyBatis?的?XML?配置文件和緩存使用步驟

    MyBatis?包含一個(gè)非常強(qiáng)大的查詢緩存特性,它可以非常方便地配置和定制,這篇文章主要介紹了MyBatis的XML配置文件和緩存,需要的朋友可以參考下
    2022-01-01
  • Spring注解驅(qū)動(dòng)之@EventListener注解使用方式

    Spring注解驅(qū)動(dòng)之@EventListener注解使用方式

    這篇文章主要介紹了Spring注解驅(qū)動(dòng)之@EventListener注解使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 使用Java進(jìn)行Json數(shù)據(jù)的解析(對(duì)象數(shù)組的相互嵌套)

    使用Java進(jìn)行Json數(shù)據(jù)的解析(對(duì)象數(shù)組的相互嵌套)

    下面小編就為大家?guī)?lái)一篇使用Java進(jìn)行Json數(shù)據(jù)的解析(對(duì)象數(shù)組的相互嵌套)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08
  • Mybatis-Plus開(kāi)發(fā)提速器generator的使用

    Mybatis-Plus開(kāi)發(fā)提速器generator的使用

    本文就介紹這款基于Mybatis-Plus的代碼自助生成器,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07

最新評(píng)論