Skip to content

Instantly share code, notes, and snippets.

@VincentRoma
Created December 12, 2018 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VincentRoma/5a2f4debbef2755972012d845cf40b1f to your computer and use it in GitHub Desktop.
Save VincentRoma/5a2f4debbef2755972012d845cf40b1f to your computer and use it in GitHub Desktop.
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