提交 8d873e6c 编写于 作者: W wizardforcel

2020-12-20 23:00:30

上级 103a65be
......@@ -298,8 +298,8 @@ return np.mean(np.abs((A - B) / A)) * 100
在使用这两个函数将测试集与预测进行比较之后,我们得到以下结果:
* De-normalized **RMSE** : $399.6
* 非规范化的 **MAPE** :8.4%
* 非规范化的 **RMSE**: 399.6 美元
* 非规范化的 **MAPE**:8.4%
这表明我们的预测与实际数据的平均差异约为 399 美元。 这意味着与实际比特币价格相差约 8.4%。
......@@ -317,7 +317,7 @@ return np.mean(np.abs((A - B) / A)) * 100
$ jupyter notebook
```
2. Open the URL provided by the application in your browser and open the Jupyter Notebook named `Activity_6_Creating_an_active_training_environment.ipynb`:
2. 在浏览器中打开应用程序提供的 URL,然后打开名为`Activity_6_Creating_an_active_training_environment.ipynb`的 Jupyter 笔记本:
![Activity 6 – Creating an Active Training Environment](img/image03_13.jpg)
......@@ -339,7 +339,7 @@ return np.mean(np.abs((A - B) / A)) * 100
$ test = pd.read_csv('data/test_dataset.csv')
```
7. Also, load our previously compiled model using the following command:
7. 另外,使用以下命令加载先前编译的模型:
```py
$ model = load_model('bitcoin_lstm_v0.h5')
......@@ -353,7 +353,7 @@ return np.mean(np.abs((A - B) / A)) * 100
$ result = model.evaluate(x=X_test, y=Y_test, verbose=0)
```
9. Each evaluation result is now stored in the variable `evaluated_weeks`. That variable is a simple array containing the sequence of MSE predictions for every week in the test set. Go ahead and also plot these results:
9. 现在,每个评估结果都存储在变量`evaluated_weeks`中。 该变量是一个简单的数组,其中包含测试集中每个星期的 MSE 预测序列。 继续并绘制以下结果:
![Activity 6 – Creating an Active Training Environment](img/image03_07.jpg)
......@@ -361,7 +361,7 @@ return np.mean(np.abs((A - B) / A)) * 100
正如我们在本课程中讨论的那样,MSE 损失函数很难解释。 为了促进我们对模型性能的理解,我们还每周在测试集中调用方法`model.predict()`,并将其预测结果与该集的值进行比较。
10. Navigate to the section **Interpreting Model Results** and execute the code cells under the sub-header **Make Predictions**. Notice that we are calling the method `model.predict()`, but with a slightly different combination of parameters. Instead of using both `X` and `Y` values, we only use `X`:
10. 导航至`Interpreting Model Results`部分,并在子标题`Make Predictions`下执行代码单元。 注意,我们正在调用方法`model.predict()`,但是参数的组合稍有不同。 我们不使用`X``Y`值,而是只使用`X`
```py
predicted_weeks = []
......@@ -379,7 +379,7 @@ return np.mean(np.abs((A - B) / A)) * 100
我们还将进行相同的比较,但使用非标准化值。 为了使我们的数据不规范,我们必须首先确定测试集和预测之间的等效周。 然后,我们获取该周的第一个价格值,并使用它来逆转*第 2 课,模型体系结构*中的点相对标准化方程。
11. 导航到标题“非规范化预测”,然后执行该标题下的所有单元格。
12. In this section, we defined the function `denormalize(),` which performs the complete de-normalization process. Different than other functions, this function takes in a Pandas DataFrame instead of a NumPy array. We do so for using dates as an index. This is the most relevant cell block from that header:
12. 在本节中,我们定义了函数`denormalize()`,该函数执行完整的反规范化过程。 与其他函数不同,此函数采用 Pandas 数据帧而不是 NumPy 数组。 我们这样做是为了将日期用作索引。 这是与该标头最相关的单元格块:
```py
predicted_close = predicted.groupby('iso_week').apply(
......@@ -394,7 +394,7 @@ return np.mean(np.abs((A - B) / A)) * 100
LSTM 网络使用 MSE 值作为其损耗函数。 但是,正如课程中所讨论的,MSE 值难以解释。 为了解决这个问题,我们实现了两个功能(从脚本`utilities.py`加载),它们实现了功能 RMSE 和 MAPE。 这些函数通过返回与原始数据相同的比例尺的度量值,并比较比例尺的百分比差异,从而为我们的模型增加了可解释性。
13. Navigate to the header De-normalizing Predictions and load two functions from the `utilities.py` script:
13. 导航至标题`De-normalizing Predictions`并从`utilities.py`脚本中加载两个函数:
```py
from scripts.utilities import rmse, mape
......@@ -422,7 +422,7 @@ return np.mean(np.abs((A - B) / A)) * 100
model = load_model('bitcoin_lstm_v0.h5')
```
15. Now, run the `train_model()` function again, but with different parameters, indicating a new run version:
15. 现在,再次运行`train_model()`函数,但使用不同的参数,指示新的运行版本:
```py
train_model(X=X_train, Y=Y_validate, version=0, run_number=0)
......@@ -726,7 +726,7 @@ MAPE(整个系列)
$ tensorboard --logdir=logs/
```
2. Open the URL that appears on the screen and leave that browser tab open, as well. Also, start a Jupyter Notebook instance with:
2. 打开出现在屏幕上的 URL,并使该浏览器选项卡也保持打开状态。 另外,使用以下命令启动 Jupyter 笔记本实例:
```py
$ jupyter notebook
......@@ -734,13 +734,13 @@ MAPE(整个系列)
打开出现在其他浏览器窗口中的 URL。
3. Now, open the Jupyter Notebook called `Activity_7_Optimizing_a_deep_learning_model.ipynb` and navigate to the title of the Notebook and import all required libraries.
3. 现在,打开名为`Activity_7_Optimizing_a_deep_learning_model.ipynb`的 Jupyter 笔记本,并导航至笔记本的标题并导入所有必需的库。
我们将像以前的活动一样加载火车和测试数据。 我们还将使用实用程序功能`split_lstm_input()`将分为训练组和测试组。
在本笔记本的每个部分中,我们将在模型中实施新的优化技术。 每次这样做,我们都会训练一个新模型并将其训练后的实例存储在描述模型版本的变量中。 例如,在本笔记本中,我们的第一个模型`bitcoin_lstm_v0,`被称为`model_v0`。 在笔记本的最后,我们使用 MSE,RMSE 和 MAPE 评估所有模型。
4. Now, in the open Jupyter Notebook, navigate to the header **Adding Layers and Nodes**. You will recognize our first model in the next cell. This is the basic LSTM network that we built in *Lesson 2*, *Model Architecture*. Now, we have to add a new LSTM layer to this network.
4. 现在,在打开的 Jupyter 笔记本中,导航至标题`Adding Layers and Nodes`。 您将在下一个单元格中识别出我们的第一个模型。 这是我们在第 2 课,“模型架构”中构建的基本 LSTM 网络。 现在,我们必须向该网络添加一个新的 LSTM 层。
利用本课中的知识,继续并添加新的 LSTM 层,编译和训练模型。
......@@ -750,7 +750,7 @@ MAPE(整个系列)
图 14:运行 TensorBoard 实例,该实例显示了许多不同的模型运行。 TensorBoard 对于实时跟踪模型训练非常有用。
5. Now, navigate to the header **Epochs**. In this section, we are interested in exploring different magnitudes of epochs. Use the utility function `train_model()` to name different model versions and runs:
5. 现在,导航至标题`Epochs`。 在本节中,我们有兴趣探索不同周期的大小。 使用实用程序函数`train_model()`来命名不同的模型版本并运行:
```py
train_model(model=model_v0, X=X_train, Y=Y_validate, epochs=100, version=0, run_number=0)
......@@ -762,7 +762,7 @@ MAPE(整个系列)
在尝试了新纪元之后,请转到下一个优化技术:激活函数。
6. Now, navigate to the header **Activation Functions** in the Notebook. In this section, you only need to change the following variable:
6. 现在,导航至笔记本中的标题`Activation Functions`。 在本节中,您只需要更改以下变量:
```py
activation_function = "tanh"
......@@ -773,11 +773,11 @@ MAPE(整个系列)
我们的最终选择是尝试不同的正则化策略。 这显然更加复杂,并且可能需要花费一些迭代才能注意到任何收益,尤其是数据量很少时。 此外,添加正则化策略通常会增加网络的培训时间。
7. 现在,导航至笔记本中的标题**正则化策略**。 在本部分中,您需要实现`Dropout()`正则化策略。 找到合适的位置放置该步骤并将其实施到我们的模型中。
8. You can also try the L2 regularization here, as well (or combine both). Do the same as with `Dropout()`, but now using `ActivityRegularization(l2=0.0001)`.
8. 您也可以在这里尝试进行 L2 正则化(或将两者结合使用)。 与`Dropout()`相同,但现在使用`ActivityRegularization(l2=0.0001)`
最后,让我们使用 RMSE 和 MAPE 评估我们的模型:
9. Now, navigate to the header **Evaluate Models** in the Notebook. In this section, we will evaluate the model predictions for the next 19 weeks of data in the test set. Then, we will compute the RMSE and MAPE of the predicted series versus the test series.
9. 现在,导航至笔记本中的标题`Evaluate Models`。 在本节中,我们将评估测试集中未来 19 周数据的模型预测。 然后,我们将计算预测序列与测试序列的 RMSE 和 MAPE。
我们已经实现了与活动 6 相同的评估技术,所有这些技术都包含在实用程序函数中。 只需运行本节中的所有单元格,直到笔记本末尾即可查看结果。
......
......@@ -181,11 +181,11 @@ M.train(model_data[i*7:7*(40 + i) + 7])
$ jupyter notebook
```
2. Open the URL provided by the application in your browser and open the Jupyter Notebook named `Activity_8_Re_training_a_model_dynamically.ipynb`.
2. 在浏览器中打开应用程序提供的URL,然后打开名为`Activity_8_Re_training_a_model_dynamically.ipynb`的 Jupyter 笔记本。
现在,我们将从`cryptonic: Model()`和`CoinMarketCap()`加载这两个类。 这些类有助于操纵模型的过程以及从网站 [CoinMarketCap](https://coinmarketcap.com/) 获取数据的过程。
3. In the Jupyter Notebook instance, navigate to the header **Fetching Real-Time Data**. We will now be fetching updated historical data from CoinMarketCap. Simply call the method:
3. 在 Jupyter 笔记本实例中,导航至标题`Fetching Real-Time Data`。 现在,我们将从`CoinMarketCap`获取更新的历史数据。 只需调用方法:
```py
$ historic_data = CoinMarketCap.historic()
......@@ -195,7 +195,7 @@ M.train(model_data[i*7:7*(40 + i) + 7])
数据实际上包含了与我们之前的数据集相同的变量。 但是,许多数据来自较早时期。 与几年前的价格相比,最近的比特币价格已经大幅波动。 在模型中使用此数据之前,请确保将其过滤为 2017 年 1 月 1 日之后的日期。
4. Using the Pandas API, filter the data for only the dates available in 2017:
4. 使用 Pandas API,仅过滤 2017 年可用日期的数据:
```py
$ model_data = # filter the dataset using pandas here
......@@ -205,7 +205,7 @@ M.train(model_data[i*7:7*(40 + i) + 7])
类`Model()`编译到目前为止我们在所有活动中编写的所有代码。 在本活动中,我们将使用该类来构建,训练和评估我们的模型。
5. Using the `Model()` class, we now train a model using the preceding filtered data:
5. 使用`Model()`类,我们现在使用前面的过滤数据训练模型:
```py
M = Model(data=model_data,
......@@ -227,7 +227,7 @@ M.train(model_data[i*7:7*(40 + i) + 7])
为此,我们将模型配置为使用 40 周来预测一周。 现在,我们要使用剩下的 10 个完整星期来创建 40 个星期的重叠期间,一次包括这 10 个星期中的一个,并针对其中每个期间重新训练模型。
6. Navigate to the header **Re-Train Old Model** in the Jupyter Notebook. Now, complete the range function and the `model_data` filtering parameters, using an index to split the data in overlapping groups of seven days. Then, re-train our model and collect the results:
6. 导航到 Jupyter 笔记本中的标题`Re-Train Old Model`。 现在,使用索引将数据分成 7 天的重叠组,完成`range`函数和`model_data`过滤参数。 然后,重新训练我们的模型并收集结果:
```py
results = []
......@@ -441,7 +441,7 @@ $ docker-compose up -d
BITCOIN_START_DATE = # Use other date here
```
4. As a final step, deploy your web application locally using `docker-compose,` as follows:
4. 最后,使用`docker-compose`在本地部署 Web 应用程序,如下所示:
```py
docker-compose up
......@@ -449,7 +449,9 @@ $ docker-compose up -d
您应该在终端上看到活动日志,包括模型中的训练时期。
5. After the model has been trained, you can visit your application on `http://localhost:5000` and make predictions on `http://localhost:5000/predict` :![Activity 9 – Deploying a Deep Learning Application](img/image04_02.jpg)
5. 训练完模型后,您可以在`http://localhost:5000`上访问您的应用程序,并在`http://localhost:5000/predict`上进行预测:
![Activity 9 – Deploying a Deep Learning Application](img/image04_02.jpg)
> 图 3:本地部署的加密应用程序的屏幕快照
......
......@@ -168,12 +168,12 @@
让我们通过一个示例来计算概率 *P(F,a / E)*。 让一个特定的英语句子由五个单词的句子表示。 *e =(e <sub>1</sub> ,e <sub>2</sub> ,e <sub>3</sub> ,e <sub>4</sub> ,e <sub>5</sub> )*,实际上这是实际法语句子的正确翻译。 *f =(f <sub>1</sub> ,f <sub>2</sub> ,f <sub>3</sub> ,f <sub>4</sub> ,f <sub>5</sub> ,f <sub>6</sub> )*。 另外,让单词的相应对齐方式如下:
* *e <sub>1</sub>**f <sub>6</sub>*
*`e`<sub>`2`</sub> →*与法语*中的任何单词均不对应
*`e`<sub>`3`[</sub>→ *f <sub>3</sub>* , *f <sub>4</sub>*
* *e <sub>4</sub>*`f`*<sub>1</sub>*
* *e <sub>5</sub>*`f`*<sub>2</sub>*
* *f <sub>5</sub>**不对应英语中的任何单词*
* `e1 -> f6`
* `e2 ->`不对应法语中的任何单词
* `e3 -> f3, f4`
* `e4 -> f1`
* `e5 -> f2`
* `f5 ->`不对应英语中的任何单词
由于这是一个概率模型,因此该算法将尝试使用具有不同对齐方式的不同英语句子,在给定法语句子的情况下,其中具有正确对齐方式的正确英语句子应该具有最高的概率。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册