| Simple Sales Prediction
| |
|
Now make the prediction for next year January or x=13 ...
val p1=coeff_df.withColumn("pred13", col("w0")+ lit(13)*col("w1") )
val pred_df=sale_df.join( p1, Seq("shop","product"), "leftouter").drop("w0").drop("w1").
withColumn("next_jan",udfRound( p1("pred13") ) ).drop("pred13")
Result:
pred_df.orderBy("shop","product").show()
+----------+-------+----+----+----+----+----+----+----+----+----+----+----+----+--------+
| shop|product| jan| feb| mar| apr| may| jun| jul| aug| sep| oct| nov| dec|next_jan|
+----------+-------+----+----+----+----+----+----+----+----+----+----+----+----+--------+
| megamart| bread| 371| 432| 425| 524| 468| 414|null| 487| 493| 517| 473| 470|508.3085|
| megamart| cheese| 51| 56| 63|null| 66| 66| 50| 56| 58|null| 48| 50| 51.9646|
| megamart| milk|null| 29| 26| 30| 26| 29| 29| 25| 27|null| 28| 30| 28.1958|
| megamart| nuts|1342|1264|1317|1425|1326|1187|1478|1367|1274|1380|1584|1156|1362.894|
| megamart| razors| 599|null| 500| 423| 574| 403| 609| 520| 495| 577| 491| 524|516.0467|
| megamart| soap|null| 7| 8| 9| 9| 8| 9| 9| 9| 6| 6| 8| 7.4|
|superstore| bread| 341| 398| 427| 344| 472| 370| 354| 406|null| 407| 465| 402|428.2097|
|superstore| cheese| 57| 52|null| 54| 62|null| 56| 66| 46| 63| 55| 53| 56.4189|
|superstore| milk| 33|null|null| 33| 30| 36| 35| 34| 38| 32| 35| 29| 33.3631|
|superstore| nuts|1338|1369|1157|1305|1532|1231|1466|1148|1298|1059|1216|1231|1183.894|
|superstore| razors| 360| 362| 366| 352| 365| 361| 361| 353| 317| 335| 290| 406|339.3788|
|superstore| soap| 8| 8| 7| 8| 6|null| 7| 7| 7| 8| 6|null| 6.5|
+----------+-------+----+----+----+----+----+----+----+----+----+----+----+----+--------+
See last column: next_jan .
| |