Created
December 12, 2018 11:15
-
-
Save VincentRoma/5a2f4debbef2755972012d845cf40b1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cloudera.tsexamples | |
import com.cloudera.sparkts.models.ARIMA | |
import org.apache.spark.mllib.linalg.Vectors | |
/** | |
* An example showcasing the use of ARIMA in a non-distributed context. | |
*/ | |
object SingleSeriesARIMA { | |
def main(args: Array[String]): Unit = { | |
// The dataset is sampled from an ARIMA(1, 0, 1) model generated in R. | |
val lines = scala.io.Source.fromFile("../data/R_ARIMA_DataSet1.csv").getLines() | |
val ts = Vectors.dense(lines.map(_.toDouble).toArray) | |
val arimaModel = ARIMA.fitModel(1, 0, 1, ts) | |
println("coefficients: " + arimaModel.coefficients.mkString(",")) | |
val forecast = arimaModel.forecast(ts, 20) | |
println("forecast of next 20 observations: " + forecast.toArray.mkString(",")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment