# Extrapolate data from Predict function

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.

• 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. – corey979 Nov 22 '16 at 19:55
• @corey979 Thanks. Also, is there a way to plot the current data along with the predicted data on a graph? – aL_eX Nov 22 '16 at 20:16
• I'm getting nonsensical outputs, but I'm unfamiliar with Association and Dataset, so I'll restrain from causing confusion. – corey979 Nov 22 '16 at 20:54

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}]}]


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]]
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.3234711289405823, "perplexity": 6115.120792313652}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-47/segments/1573496668004.65/warc/CC-MAIN-20191114053752-20191114081752-00549.warc.gz"}