Simple Sales Prediction
 
05_product
20160616
    val d4=d3.withColumn("p_xy", col("xdif")*col("ydif") ).
              withColumn("p_xx", col("xdif")*col("xdif") )

    // apply cosmetics: round off
    val d5=d4.withColumn("pxy", udfRound( d4("p_xy") )).
              withColumn("pxx", udfRound( d4("p_xx") )).
              drop("p_xy").
              drop("p_xx") 

Result:

d5.orderBy("shop","product","x").show()

+--------+-------+---+---+------+--------+-------+--------+---------+-------+   
|    shop|product|  x|  y| avg_x|   avg_y|   xdif|    ydif|      pxy|    pxx|
+--------+-------+---+---+------+--------+-------+--------+---------+-------+
|megamart|  bread|  1|371|6.4545|461.2727|-5.4545|-90.2727| 492.3924|29.7515|
|megamart|  bread|  2|432|6.4545|461.2727|-4.4545|-29.2727| 130.3952|19.8425|
|megamart|  bread|  3|425|6.4545|461.2727|-3.4545|-36.2727|  125.304|11.9335|
|megamart|  bread|  4|524|6.4545|461.2727|-2.4546| 62.7273|-153.9705|  6.025|
|megamart|  bread|  5|468|6.4545|461.2727|-1.4546|  6.7273|  -9.7856| 2.1158|
|megamart|  bread|  6|414|6.4545|461.2727|-0.4546|-47.2727|  21.4901| 0.2066|
|megamart|  bread|  8|487|6.4545|461.2727| 1.5454| 25.7273|  39.7589| 2.3882|
|megamart|  bread|  9|493|6.4545|461.2727| 2.5454| 31.7273|  80.7586|  6.479|
|megamart|  bread| 10|517|6.4545|461.2727| 3.5455| 55.7273| 197.5811|12.5705|
|megamart|  bread| 11|473|6.4545|461.2727| 4.5455| 11.7273|  53.3064|20.6615|
|megamart|  bread| 12|470|6.4545|461.2727| 5.5455|  8.7273|  48.3972|30.7525|
|megamart| cheese|  1| 51|   6.4|    56.4|   -5.4|    -5.4|    29.16|  29.16|
|megamart| cheese|  2| 56|   6.4|    56.4|   -4.4|    -0.4|     1.76|  19.36|
|megamart| cheese|  3| 63|   6.4|    56.4|   -3.4|     6.6|   -22.44|11.5599|
|megamart| cheese|  5| 66|   6.4|    56.4|-1.4001|     9.6|  -13.441| 1.9602|
|megamart| cheese|  6| 66|   6.4|    56.4|-0.4001|     9.6|   -3.841|   0.16|
|megamart| cheese|  7| 50|   6.4|    56.4| 0.5999|    -6.4|  -3.8394| 0.3598|
|megamart| cheese|  8| 56|   6.4|    56.4| 1.5999|    -0.4|    -0.64| 2.5596|
|megamart| cheese|  9| 58|   6.4|    56.4| 2.5999|     1.6|   4.1598| 6.7594|
|megamart| cheese| 11| 48|   6.4|    56.4|    4.6|    -8.4|   -38.64|21.1599|
+--------+-------+---+---+------+--------+-------+--------+---------+-------+
 
Notes by Data Munging Ninja. Generated on nini:/home/willem/sync/20151223_datamungingninja/simplesalesprediction at 2016-06-25 10:02