【发布时间】:2021-09-26 18:50:09
【问题描述】:
关于使用 SparkML 和朴素贝叶斯进行预测/预测的小问题。
我有一个很简单的数据集,就是时间戳,代表一天,当天卖出了多少煎饼:
dataSetPancakes.show();
+----------+-----+
| time|label|
+----------+-----+
|1622505600| 1|
|1622592000| 0|
|1622678400| 3|
|1622764800| 1|
|1622851200| 1|
|1622937600| 1|
|1623024000| 1|
|1623110400| 2|
|1623196800| 2|
|1623283200| 0|
+----------+-----+
only showing top 10 rows"
很简单,我就是想预测一下明天,后天等会卖多少煎饼……
因此,我尝试了朴素贝叶斯模型,按照这里的教程https://spark.apache.org/docs/latest/ml-classification-regression.html#naive-bayes,我写道:
VectorAssembler vectorAssembler = new VectorAssembler().setInputCols(new String[]{"time"}).setOutputCol("features");
Dataset<Row> vectorData = vectorAssembler.transform(dataSetPancakes);
NaiveBayes naiveBayes = new NaiveBayes();
NaiveBayesModel model = naiveBayes.fit(vectorData);
Dataset<Row> predictions = model.transform(vectorData);
predictions.show();
model.predict(new DenseVector(new double[]{getTomorrowTimestamp()})));
我什至会看到如下结果:
-RECORD 0--------------------------------------------------------------------------------------------------------------
time | 1622505600
label | 1
features | [1.6225056E9]
rawPrediction | [-0.9400072584914714,-1.0831081021321447,-1.702147310538368,-2.5494451709255714,-4.564348191467836]
probability | [0.39062499999999994,0.33854166666666663,0.18229166666666666,0.07812500000000001,0.01041666666666667]
prediction | 0.0
-RECORD 1--------------------------------------------------------------------------------------------------------------
time | 1622592000
label | 0
features | [1.622592E9]
rawPrediction | [-0.9400072584914714,-1.0831081021321447,-1.702147310538368,-2.5494451709255714,-4.564348191467836]
probability | [0.39062499999999994,0.33854166666666663,0.18229166666666666,0.07812500000000001,0.01041666666666667]
prediction | 0.0
但至于预测本身,不幸的是,它总是显示明天的 0.0。
请问这个问题的根本原因是什么?
谢谢
【问题讨论】:
标签: java apache-spark machine-learning naivebayes