官术网_书友最值得收藏!

Keras and TensorFlow background

I mentioned earlier that Keras is an API, a frontend if you will, for several deep learning backends. It was originally available only for Python but has been available in R since, mid-2017. It is important to spend some time reviewing its capabilities at its documentation source: https://keras.io/why-use-keras/.

I must confess my colleagues brought me into Keras and using TensorFlow kicking and screaming. If I can get this to work, I would say that you certainly can. I must thank them, as it is very powerful, even though I have a slight bias toward MXNet. As the old saying goes, it is tough to teach old dogs new tricks!

The backend of choice, of course, is TensorFlow. We must now take a few sentences to put in plain English what a tensor is, and what TensorFlow is. A tensor is an n-dimensional array. Thus, a vector is a one-dimensional tensor, a matrix is a two-dimensional tensor and so forth. Let's say you have a multivariate time series, which would consist of a three-dimensional tensor: one dimension is the observations or length of your data, another dimension is the features, and another the timesteps or, more concretely, the lagged values. TensorFlow as a backend is an open source platform, created by Google, that uses tensors, of course, for high-performance and scalable computation. The base frontend for TensorFlow is Python. Therefore, to use Keras and R as the frontend, you must install Python, in particular the Python platform Anaconda: https://www.anaconda.com/.

So, if installing Anaconda becomes an issue, then the following exercise will require you to use a different backend, which is outside the scope of this discussion. Let's look at how to get this up and running. Keep in mind that I'm using a Windows-based computer:

As a caveat, it is important to inform you that I in no way guarantee that the following code will work for you as I exactly lay it out. I've installed this on several computers, and each time I encountered different problems that required me to search the internet for a specific solution. The one common factor is that you have installed Anaconda on your computer and that it is fully functional.
# Install reticulate package as it allows R to call python
> install.packages("reticulate")

> install.packages("keras")

> keras::install_keras() # loads the necessary python packages and may take some time to complete

> library(keras)

> library(reticulate)

That was the code that worked for me on this laptop. Again, your results may vary. Also, note that I've run into a number of issues that required me to run install_keras() again to get it working properly.

Assuming all is well, let's get our data loaded.

主站蜘蛛池模板: 岑巩县| 罗平县| 明光市| 独山县| 平安县| 民勤县| 恩施市| 龙游县| 兴隆县| 皋兰县| 华蓥市| 七台河市| 天水市| 清徐县| 茶陵县| 霸州市| 凤冈县| 大洼县| 洪江市| 阜康市| 马鞍山市| 鲁甸县| 台湾省| 邛崃市| 抚宁县| 溧水县| 绩溪县| 屯留县| 怀宁县| 铜梁县| 托里县| 高要市| 措美县| 临洮县| 安龙县| 大新县| 连江县| 宁晋县| 通海县| 澄迈县| 万荣县|