Developing the model

To develop the model, we can either use an IDE, or we can use the Azure Notebook. In our example, we will use Jupyter Notebook.


For your convenience, the Jupyter Notebook of this exercise is available at the official repository at https://github.com/PacktPublishing/Hands-On-Industrial-Internet-of-Things.

To develop our model, follow these steps:

From the command console, start the Jupyter server with the following command:

$ jupyter notebook

Then, we need to create a new notebook by clicking  on New | Python 3 from the menu on the right. As we learned before, we need an instance of the Azure Notebook workbench. The following code instantiates an Azure workbench, stores this information in a local file so that it can be loaded later, and starts an experiment called wind-turbine-experiment:

import azureml.core

print(azureml.core.VERSION)
subscription_id = '<my subscription id>'
from azureml.core import Workspace
ws = Workspace.create(name='iiot-book-ml-workspace',
subscription_id=subscription_id,
resource_group='iiot-book-res',
create_resource_group=True,
location='westeurope' # or other supported Azure region
)

# store information on the configuration file.
ws.write_config()

from azureml.core import Experiment
# create a new experiment
exp = Experiment(workspace=ws, name='wind-turbine-experiment')
# start a run
run = exp.start_logging()

We can now write our physics-based model. This model is the same model as we developed in Chapter 14, Implementing a Digital Twin - Advanced Analytics. The code is printed here for convenience:

# model
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

def wind_turbine_model(x):

# cut-in speed vs cut-out speed
if x<4.5 or x>21.5:
return 0.0

# standard operability
return 376.936 - 195.8161*x
+ 33.75734*x**2 - 2.212492*x**3
+ 0.06309095*x**4 - 0.0006533647*x**5

reference_power = [wind_turbine_model(x) for x in range(0,30)]

# show data and reference
fig, ax = plt.subplots()
#ax.plot(df.wind_speed_ms, df.power_generated_kw,'.r')
ax.plot(reference_power,'k')
ax.set_xlabel('wind speed (m/s)')
ax.set_ylabel('power (kW)')
plt.show()

Finally, we can visualize the output on the Azure ML experiment with the following code:

run.log_list('Wind Turbine Model', reference_power) # log a list of values

# finish the run
run.complete()
print(run.get_portal_url())

The following screenshot shows the expected output:

The wind turbine on Azure ML

The model works as expected, which means we can now deploy it on the Azure cloud.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset