<commit_before>---
layout: post
title: "Time Series Deep Learning, Part 2: Predicting Sunspot Frequency with Keras LSTM In R"
author: "<NAME>, <NAME>"
date:   2018-07-01 07:45:01
categories: [Timeseries-Analysis]
tags: [R-Project, R, Time Series, Deep Learning, Keras, TensorFlow, Backtesting, tidyverse, tibbletime, timetk, keras, rsample, recipes, yardstick]
image: 2018-07-01-keras-lstm-sunspots2/backtested_test.png
---



One of the ways __Deep Learning can be used in business__ is to improve the accuracy of time series forecasts (prediction). We recently showed how a [Long Short Term Memory (LSTM) Models developed with the Keras library in R](http://www.business-science.io/timeseries-analysis/2018/04/18/keras-lstm-sunspots-time-series-prediction.html) could be used to take advantage of _autocorrelation_ to predict the next 10 years of monthly Sunspots (a solar phenomenon that's tracked by NASA). In this article, we teamed up with RStudio to take another look at the Sunspots data set, this time implementing some really advanced Deep Learning functionality available with [TensorFlow for R](https://tensorflow.rstudio.com). <NAME>, TF Developer Advocate at RStudio, put together an amazing Deep Learning tutorial using `keras` for [implementing Keras in R](https://tensorflow.rstudio.com/keras/) and `tfruns`, a [suite of tools](https://tensorflow.rstudio.com/blog/tfruns.html) for trackingtracking, visualizing, and managing TensorFlow training runs and experiments from R. Sounds amazing, right? It is! __Let's get started with this Deep Learning Tutorial!__


## Related Articles In This Series

- [Time Series Deep Learning: Forecasting Sunspots With Keras Stateful LSTM In R](http://www.business-science.io/timeseries-analysis/2018/04/18/keras-lstm-sunspots-time-series-prediction.html)

- You can also find this article on [RStudio's TensorFlow Blog](https://tensorflow.rstudio.com/blog/sunspots-lstm.html).


## Learning Trajectory

In this __DEEP LEARNING TUTORIAL___, you will learn:

* [How Time Series Deep Learning can be used in business](#dl-in-business)

* [Forecasting Sunspots With Deep Learning](#dl-sunspots)

* [How To Build The LSTM](#lstm)

* [Backtesting The LSTM Model](#backtesting)

In fact, one of the coolest things you'll develop is this plot of backtested LSTM forecasts.

![Backtested LSTM Forecasts](/assets/2018-07-01-keras-lstm-sunspots2/backtested_test.png)


<p class="text-center date">Backtested LSTM Forecasts</p>

## Time Series Deep Learning In Business <a class="anchor" id="dl-in-business"></a> 

> Introduction by <NAME>, Founder of Business Science

Time Series Forecasting is a key area that can lead to Return On Investment (ROI) in a business. Think about this: __A 10% improvement in forecast accuracy can save an organization millions of dollars__. How is this possible? Let's find out.  

We'll take [NVIDIA](http://www.nvidia.com/page/home.html), a semiconductor manufacturer that manufactures state-of-the-art chips for _Artificial Intelligence (AI)_ and _Deep Learning (DL)_, as an example. _NVIDIA_ builds [Graphics Processing Unitis or GPUs](https://en.wikipedia.org/wiki/Graphics_processing_unit), which are necessary for the computational intensitity resulting from the massive number of numerical calculations required in high-performance Deep Learning. The chips look like this.

![NVIDIA](/assets/2018-07-01-keras-lstm-sunspots2/nvidia.png)

<p class="text-center date">Source: <a href="http://www.nvidia.com/page/home.html">NVIDIA USA</a></p>

Like all manufacturers, _NVIDIA_ needs to ___forecast demand___ for their products. Why? So they can build the right amount of chips to supply their customers. This forecast is critical and it takes a lot of skill and some luck to get this right. 

What we are talking about is the ___Sales Forecast___, which drives every manufacturing decision that NVIDIA makes. This includes how much raw material to purchase, how many people to have on staff to build the chips, and how much machining and assembly operations to budget. The more error in the sales forecast, the more unnecessary cost NVIDIA experiences because all of these activities (supply chain, inventory management, financial planning, etc) get thrown off!
<commit_msg>5 topic friday<commit_after>---
layout: post
title: "Time Series Deep Learning, Part 2: Predicting Sunspot Frequency with Keras LSTM In R"
author: "<NAME>, <NAME>"
date:   2018-07-01 07:45:01
categories: [Timeseries-Analysis]
tags: [R-Project, R, Time Series, Deep Learning, Keras, TensorFlow, Backtesting, tidyverse, tibbletime, timetk, keras, rsample, recipes, yardstick]
image: 2018-07-01-keras-lstm-sunspots2/backtested_test.png
---



One of the ways __Deep Learning can be used in business__ is to improve the accuracy of time series forecasts (prediction). We recently showed how a [Long Short Term Memory (LSTM) Models developed with the Keras library in R](http://www.business-science.io/timeseries-analysis/2018/04/18/keras-lstm-sunspots-time-series-prediction.html) could be used to take advantage of _autocorrelation_ to predict the next 10 years of monthly Sunspots (a solar phenomenon that's tracked by NASA). In this article, we teamed up with RStudio to take another look at the Sunspots data set, this time implementing some really advanced Deep Learning functionality available with [TensorFlow for R](https://tensorflow.rstudio.com). <NAME>, TF Developer Advocate at RStudio, put together an amazing Deep Learning tutorial using `keras` for [implementing Keras in R](https://tensorflow.rstudio.com/keras/) and `tfruns`, a [suite of tools](https://tensorflow.rstudio.com/blog/tfruns.html) for trackingtracking, visualizing, and managing TensorFlow training runs and experiments from R. Sounds amazing, right? It is! __Let's get started with this Deep Learning Tutorial!__


## Related Articles In This Series

- [Time Series Deep Learning: Forecasting Sunspots With Keras Stateful LSTM In R](http://www.business-science.io/timeseries-analysis/2018/04/18/keras-lstm-sunspots-time-series-prediction.html)

- You can also find this article on [RStudio's TensorFlow Blog](https://tensorflow.rstudio.com/blog/sunspots-lstm.html).


## Learning Trajectory

In this __DEEP LEARNING TUTORIAL___, you will learn:

* [How Time Series Deep Learning can be used in business](#dl-in-business)

* [Forecasting Sunspots With Deep Learning](#dl-sunspots)

* [How To Build The LSTM](#lstm)

* [Backtesting The LSTM Model](#backtesting)

In fact, one of the coolest things you'll develop is this plot of backtested LSTM forecasts.

![Backtested LSTM Forecasts](/assets/2018-07-01-keras-lstm-sunspots2/backtested_test.png)


<p class="text-center date">Backtested LSTM Forecasts</p>



<hr>

<h2 class="text-center">Interested in Learning Data Science For Business?</h2>

<p class="text-center">
Sign up for our free <strong>"5 Topic Friday" Newsletter</strong>. Every week, I'll send you the five coolest topics in data science for business that I've found that week. These could be new R packages, free books, or just some fun to end the week on. 
</p>

<p class="text-center" style="font-size:30px;">
<a href="https://mailchi.mp/business-science.io/five-topic-friday"><strong>Sign Up For Five-Topic-Friday!</strong></a> 
</p>

<hr>

## Time Series Deep Learning In Business <a class="anchor" id="dl-in-business"></a> 

> Introduction by <NAME>, Founder of Business Science

Time Series Forecasting is a key area that can lead to Return On Investment (ROI) in a business. Think about this: __A 10% improvement in forecast accuracy can save an organization millions of dollars__. How is this possible? Let's find out.  

We'll take [NVIDIA](http://www.nvidia.com/page/home.html), a semiconductor manufacturer that manufactures state-of-the-art chips for _Artificial Intelligence (AI)_ and _Deep Learning (DL)_, as an example. _NVIDIA_ builds [Graphics Processing Unitis or GPUs](https://en.wikipedia.org/wiki/Graphics_processing_unit), which are necessary for the computational intensitity resulting from the massive number of numerical calculations required in high-performance Deep Learning. The chips look like this.

![NVIDIA](/assets/2018-07-01-keras-lstm-sunspots2/nvidia.png)

<p class="text-center date">Source: <a href="http://www.nvidia.com/page/home.html">NVIDIA USA</a></p>

Like all manufacturers, _NVIDIA_ needs to ___forecast demand___ for their products. Why? So they can build the right amount of chips to supply their customers. This forecast is critical and it takes a lot of skill and some luck to get this right. 

What we are talking about is the ___Sales Forecast___, which drives every manufacturing decision that NVIDIA makes. This includes how much raw material to purchase, how many people to have on staff to build the chips, and how much machining and assembly operations to budget. The more error in the sales forecast, the more unnecessary cost NVIDIA experiences because all of these activities (supply chain, inventory management, financial planning, etc) get thrown off!

{'fraction_non_alphanumeric': 0.08866070442751463, 'fraction_numerical': 0.01435353869934857, 'mean_word_length': 5.034643570952698, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 43, 'https://': 11, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '969390', 'n_tokens_mistral': 2710, 'n_tokens_neox': 2494, 'n_words': 1085}