Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Update README, generator, and ML notebook (#7)
Browse files Browse the repository at this point in the history
* Some misc README fixes/updates
* Let the generator.py work with py3
* Update the ML notebook to latest library
  • Loading branch information
markstur authored and stevemart committed Apr 12, 2019
1 parent f28ace0 commit c5df17d
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 140 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ git clone https://github.com/IBM/db2-event-store-iot-analytics

### 2. Install IBM Db2 Event Store

You can use the Developer Edition or Enterprise Edition of IBM Db2 Event Store.
Install IBM® Db2® Event Store Developer Edition on Mac, Linux, or Windows by following the instructions [here.](https://www.ibm.com/products/db2-event-store)

* To install Db2 Event Store Developer Edition on Mac, Linux, or Windows follow the instructions [here](https://www.ibm.com/support/knowledgecenter/en/SSGNPV_1.1.3/desktop/install.html).

* The Enterprise Edition is free for pre-production and test. You are welcome to visit the [official product webpage](https://www.ibm.com/products/db2-event-store) to get the Enterprise Edition for trial.
> Note: This code pattern was developed with EventStore-DeveloperEdition 1.1.4
### 3. Add the sample IoT data asset

Expand All @@ -58,7 +56,7 @@ This repository includes a generated sample IoT dataset in CSV format that conta
Alternatively, a CSV dataset containing a user-specified number of records can be generated with the provided Python script at `data/generator.py`. A Python environment with pandas and NumPy installed is required to run the script.

```bash
cd db2-event-store-iot-analysis/data
cd db2-event-store-iot-analytics/data
python ./generator.py -c <Record Count>
```

Expand Down Expand Up @@ -121,13 +119,13 @@ If you are using the **Enterprise Edition** of Db2 Event Store, the notebook wil

If you are using the **Developer Edition** of Db2 Event Store, you need an IBM Cloud Watson Machine Learning service instance to complete the deployment. Follow these steps:

* Sign in and create the service [here](https://console.ng.bluemix.net/catalog/services/machine-learning).
* Sign in and create the service [here](https://cloud.ibm.com/catalog/services/machine-learning).
* Click on `Service credentials` and then `New credential` and `Add`.
* Use `View credentials` and copy the credentials JSON.
* You will use the JSON to set the `wml_credentials` variable in the notebook.
* The notebook will pip install watson-machine-learning-client. After the install, you usually need to restart your kernel and run the notebook again from the top.

Load the notebook, using the file **`Event_Store_Data_Analytics.ipynb`**.
Load the notebook, using the file **`Event_Store_ML_Model_Deployment.ipynb`**.

Once the model is built and deployed, you can easily send it a new measurement and get a predicted temperature (one at a time or in batches).

Expand Down
11 changes: 5 additions & 6 deletions data/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

if __name__ == "__main__":

parser = argparse.ArgumentParser(description="generates 100000 rows of sample records, or a given count of record if -c flag is specified")
parser = argparse.ArgumentParser(description="generates 1000000 rows of sample records, or a given count of record if -c flag is specified")
parser.add_argument("-c","--count", help="count of records to be generated",type=int)
args = parser.parse_args()

Expand All @@ -18,21 +18,20 @@
total_record = 1000000

np.random.seed(0)
time_now = int(round(1541019341*1000))
time_now = 1541019341*1000
record_processed = 0
df = [ ]

while record_processed < total_record:
deviceID = np.random.randint(1, 3)
sensorID = np.random.randint(1, 50)
sensorID = np.random.randint(1, 50)
env_temp = np.random.normal(24.5, 2) # ambient temp
time = long(time_now + np.random.randint(10,1500))
time_now = time
time_now += np.random.randint(10,1500)
power = np.random.normal(10, 3) # power consumption
noise = np.random.normal(0,1.5)
temp = 1.3 * env_temp + 0.5 * power + 5 + noise

df.append(dict(device=int(deviceID), sensor=int(sensorID), ts=time, env_temp=float(env_temp), power=float(power), temperature=float(temp)))
df.append(dict(device=int(deviceID), sensor=int(sensorID), ts=time_now, env_temp=float(env_temp), power=float(power), temperature=float(temp)))
record_processed += 1

df = pd.DataFrame(df)
Expand Down
Loading

0 comments on commit c5df17d

Please sign in to comment.