3
$\begingroup$

I'm trying to predict the next Close value in the S&P500 index using the following code:

data = SemanticImport["http://real-chart.finance.yahoo.com/table.csv?s=SPY&a=00&b=29&c=\
2015&d=10&e=4&f=2016&g=d&ignore=.csv"]

training = data[[;; 350]];
test = data[[351 ;;]];

p = Predict[training -> "Close", PerformanceGoal -> "Quality", Method -> "NeuralNetwork"]

I now want to find the predicted value for the 5th of November, but I'm unsure how to format this. I have tried the following, but this returns an error saying that the data is not formatted correctly.

p[DateObject[{2016, 11, 05}]]

Any help would be appreciated.

$\endgroup$
  • 1
    $\begingroup$ Examining the FullForm of data[[1]] and checking with the docs of Predict leads to p[<|"Date" -> DateObject[{2016, 11, 05}]|>], what yields 226.454. $\endgroup$ – corey979 Nov 22 '16 at 19:55
  • 1
    $\begingroup$ @corey979 Thanks. Also, is there a way to plot the current data along with the predicted data on a graph? $\endgroup$ – aL_eX Nov 22 '16 at 20:16
  • $\begingroup$ I'm getting nonsensical outputs, but I'm unfamiliar with Association and Dataset, so I'll restrain from causing confusion. $\endgroup$ – corey979 Nov 22 '16 at 20:54
2
$\begingroup$

Here is an example of comparing the predicted and true data:

Train the network using the "Date" and "Open" to predict "Close"

p = Predict[training[[All, {"Date", "Open", "Close"}]] -> "Close", 
  PerformanceGoal -> "Quality", Method -> "NeuralNetwork"]

This shows how well it performs on the training data

DateListPlot[{Normal@training[All, {"Date", "Close"}], 
  Normal@training[All, {"Date", "Open"}][All, {"Date", p}]}]

enter image description here

This shows the same for the testing data

DateListPlot[{Normal@test[All, {"Date", "Close"}], 
  Normal@test[All, {"Date", "Open"}][All, {"Date", p}]}, 
 PlotLegends -> Placed[{"data", "predicted"}, Top]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.