Skip to content

Added Java Implementation of ARIMA#8

Open
vharissh14 wants to merge 1 commit intosryza:masterfrom
vharissh14:master
Open

Added Java Implementation of ARIMA#8
vharissh14 wants to merge 1 commit intosryza:masterfrom
vharissh14:master

Conversation

@vharissh14
Copy link

#7 Closed

@devanshi7
Copy link

Hi this java code to implement ARIMA Model works for me if useful to anyone

public static void main(String args[])
{
System.setProperty("hadoop.home.dir", "C:/winutils");

	 SparkSession spark = SparkSession
		      .builder().master("local")
		      .appName("Spark-TS Example")
		      .config("spark.sql.warehouse.dir", "file:///C:/Users/devanshi/Downloads/Spark/sparkdemo/spark-warehouse/")
		      .getOrCreate();
	 
        Dataset<Double> doubleDataset = lines.map(line->Double.parseDouble(line.toString()),
			Encoders.DOUBLE());
	
	List<Double> doubleList = doubleDataset.collectAsList();
			
	Double[] doubleArray = new Double[doubleList.size()];
	doubleArray = doubleList.toArray(doubleArray);
	
	double[] values = new double[doubleArray.length];
	for(int i = 0; i< doubleArray.length; i++)
	{ 
		values[i] = doubleArray[i];
	}
	
	Vector tsvector = Vectors.dense(values);
	
	System.out.println("Ts vector:" + tsvector.toString());
	
	//ARIMAModel arimamodel = ARIMA.fitModel(1, 0, 1, tsvector, true, "css-bobyqa", null);
	ARIMAModel arimamodel = ARIMA.autoFit(tsvector, 1, 1, 1);
	
	Vector forcst = arimamodel.forecast(tsvector, 10);
	
	System.out.println("forecast of next 10 observations: " + forcst);

@hancelpv
Copy link

For those who're having trouble with spark warehouse directory, please give it the path of your input text/csv file.
Let's say my file is located in "D://data/test/tesfile.csv",
spark warehouse path should be "file:///D://data/test/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants