introduction to object oriented programming 4

Consider the task of predicting the closing price of a stock over the next 5 days. You store your predictions in an array with 5 entries corresponding to your predictions for each of the next 5 days. One week later, you decide to check how accurate your predictions were by comparing them to the actual closing prices over those 5 days, which you now know.

One way to measure the accuracy of your predictions is by using the mean absolute percentage error (MAPE), defined by

1𝑇𝐴−𝐹
𝑀= ∑| 𝑡 𝑡|×100%,

page1image8120
page1image8280

𝑇𝑡=1 𝐴𝑡

where 𝐴 is the actual closing price on day 𝑡, 𝐹 is your predicted or forecasted closing price on day 𝑡, and𝑡𝑡

𝑇 = 5 days in the current example.

Part 1: Write a method to compute and return the MAPE given two arrays actual and predicted of arbitrary lengths and a user-specified tolerance value actualTol. The method should output the MAPE for your predictions, except in the following two cases:

  • The lengths of actual and predicted do not match. In this case, return −1 and print the following message to the console: Error: Actual and predicted arrays are not of same length!
  • A value in your actual array, i.e. one of your 𝐴𝑡’s, is too close to 0, which may cause a divide-by- zero error. A value is too close to 0 if its absolute value is less than a specified tolerance value, e.g.10−9. In this case, return −1 and print the following message to the console (substituting a correct index for t): Error: Entry with index t in actual array is too close to 0!Your method should have the following header:public static double computeMAPE(double[] actual, double[] predicted, double actualTol)Part 2: Overload your method by creating a second version that predicts the same closing price for each of the days. Your actual closing price will still be an array, but your prediction will now be a single value. This overloaded method should have the following header:public static double computeMAPE(double[] actual, double predicted, double actualTol)Submit your source code in a file named MeanAbsPercentError.java! Do not include a main() methodin your submission!Sample output for the following code block:double[] actual = {1, 2, 3, 4};
    double[] predictedArray = {1, 1, 1, 1};
    double predicted = 1;
    System.out.println(computeMAPE(actual, predictedArray, 1e-9)); System.out.println(computeMAPE(actual, predicted, 1e-9));

EECS 1510 Spring 2020 Sections 009/011/093 Instructor: Dr. Kevin S. Xu Introduction to Object-Oriented Programming

47.916666666666664_x000D_
47.916666666666664_x000D_

 
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!