Jump to: navigation, search

Difference between revisions of "Meteos/ExampleLinear"

(Created page with "== Predict sales using Meteos == In this example, user creates a prediction model which predict sales by using Linear Regression. Linear Regression is one of the algorithms i...")
 
(6. Predict)
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Predict sales using Meteos ==
+
== Predict a Sales Figures using Meteos ==
  
In this example, user creates a prediction model which predict sales by using Linear Regression.
+
In this example, you create a prediction model which predict sales by using Linear Regression.  
Linear Regression is one of the algorithms in supervised learning.
 
  
''"Supervised learning is the machine learning task of inferring a function from labeled training data. The training data consist of a set of training examples. In supervised learning, each example is a pair consisting of an input object (typically a vector) and a desired output value (also called the supervisory signal).  (From Wikipedia https://en.wikipedia.org/wiki/Supervised_learning)''
+
Linear Regression is one of the algorithms in supervised learning.  
 
 
In this example, sales is the desired output value.
 
  
 
[[File:Usecase.png]]
 
[[File:Usecase.png]]
Line 15: Line 12:
 
Experiment is a workspace of Machine Learning.
 
Experiment is a workspace of Machine Learning.
  
'''$ cat json/create_template.json'''
+
You have to confirm a glance image id of meteos image, and a neutron network id before creating a template.
  {
+
 
 +
You can use a format located in '''python-meteosclient/sample/json/template.json'''
 +
 
 +
<pre>
 +
$ glance image-list | grep meteos
 +
| a6b7de0b-10ff-462c-9c86-25c8a5622a57 | meteos                          |
 +
</pre>
 +
<pre>
 +
$ neutron net-list | grep public
 +
| 4222b557-6d9f-405c-b1ff-0f454d2f35bf | public | 1f979ae3-d6b7-4d03-ba0f-9d9112581783            |
 +
</pre>
 +
<pre>
 +
$ vim sample/json/template.json
 +
</pre>
 +
<pre>
 +
$ cat sample/json/template.json
 +
{
 
     "display_name": "example-template",
 
     "display_name": "example-template",
 
     "display_description": "This is a sample template of experiment",
 
     "display_description": "This is a sample template of experiment",
     "image_id" : "c48f5dba-45be-4165-9825-f4564fecebcd",
+
     "image_id" : "a6b7de0b-10ff-462c-9c86-25c8a5622a57",
 
     "master_nodes_num": 1,
 
     "master_nodes_num": 1,
 +
    "master_flavor_id": "4",
 
     "worker_nodes_num": 2,
 
     "worker_nodes_num": 2,
     "spark_version": "1.6"
+
    "worker_flavor_id": "2",
}
+
     "spark_version": "1.6.0",
 
+
    "floating_ip_pool": "4222b557-6d9f-405c-b1ff-0f454d2f35bf"
'''$ meteos template-create --json json/create_template.json'''
+
}
 
+
</pre>
+-------------+-----------------------------------------+
+
<pre>
| Property   | Value                                  |
+
$ meteos template-create --json sample/json/template.json
+-------------+-----------------------------------------+
+
+---------------+-----------------------------------------+
| cluster_id | 0984a3e7-cd8b-4b7e-b4f0-f58dc4fc6c28    |
+
| Property     | Value                                  |
| created_at | 2016-10-20T02:10:13.483231             |
+
+---------------+-----------------------------------------+
| description | This is a sample template of experiment |
+
| cluster_id   | None                                    |
| id         | 26cbc33b-179e-4d22-8b1b-23c9a305f196   |
+
| created_at   | 2016-12-15T22:55:03.000000             |
| image_id    | c48f5dba-45be-4165-9825-f4564fecebcd    |
+
| description   | This is a sample template of experiment |
  | name       | example-template                        |
+
| id           | d3180a78-74cc-432d-9e9d-68640b18abae   |
| project_id | 5f011d076a6f4a328989c57ac7b4e501       |
+
| master_flavor | 4                                      |
| status     | available                              |
+
| master_nodes | 1                                      |
  +-------------+-----------------------------------------+
+
| name         | example-template                        |
 +
| project_id   | 4034bb3cd9324776a68c140fdd18baa4       |
 +
| spark_version | 1.6.0                                  |
 +
| status       | available                              |
 +
| user_id      | 64ad04e101df40b4b51e5f370a83412c        |
 +
| worker_flavor | 2                                      |
 +
| worker_nodes | 2                                      |
 +
+---------------+-----------------------------------------+
 +
</pre>
  
 
=== 2. Create a experiment from template ===
 
=== 2. Create a experiment from template ===
  
 
Create a experiment by using template created in the above step.
 
Create a experiment by using template created in the above step.
 +
You have to confirm a neutron private network id and create keypair before creating a template.
  
'''$ cat json/create_experiment.json'''
+
You can use a format located in '''python-meteosclient/sample/json/experiment.json'''
{
+
 
 +
<pre>
 +
$ nova keypair-add key1 > ~/key1.pem && chmod 600 ~/key1.pem
 +
</pre>
 +
<pre>
 +
$ neutron net-list | grep private
 +
| e4fcc49c-48e5-48f8-9599-bb5eba1339c9 | private | e15c24a5-dfdd-4428-b27d-9827b35600c0 10.0.0.0/26 |
 +
</pre>
 +
<pre>
 +
$ vim sample/json/experiment.json
 +
</pre>
 +
<pre>
 +
$ cat sample/json/experiment.json
 +
{
 
     "display_name": "example-experiment",
 
     "display_name": "example-experiment",
 
     "display_description": "This is a sample experiment",
 
     "display_description": "This is a sample experiment",
 
     "key_name": "key1",
 
     "key_name": "key1",
     "net_id": "bc85cb2a-53ad-4375-801e-ed507d416e09",
+
     "neutron_management_network": "e4fcc49c-48e5-48f8-9599-bb5eba1339c9",
     "template_id": "26cbc33b-179e-4d22-8b1b-23c9a305f196"
+
     "template_id": "d3180a78-74cc-432d-9e9d-68640b18abae"
}
+
}
 +
</pre>
 +
<pre>
 +
$ meteos experiment-create --json sample/json/experiment.json
 +
+--------------------+--------------------------------------+
 +
| Property          | Value                                |
 +
+--------------------+--------------------------------------+
 +
| created_at        | 2016-12-15T22:56:51.000000          |
 +
| description        | This is a sample experiment          |
 +
| id                | fcc8d055-e801-4652-af8c-5aabedbf0286 |
 +
| key_name          | key1                                |
 +
| management_network | e4fcc49c-48e5-48f8-9599-bb5eba1339c9 |
 +
| name              | example-experiment                  |
 +
| project_id        | 4034bb3cd9324776a68c140fdd18baa4    |
 +
| status            | creating                            |
 +
| user_id            | 64ad04e101df40b4b51e5f370a83412c    |
 +
+--------------------+--------------------------------------+
 +
</pre>
  
'''$ meteos experiment-create --json json/create_experiment.json'''
+
Meteos creates a experiment using OpenStack Sahara spark plugin.
  
+-------------+--------------------------------------+
+
You can see a sahara cluster and nova VMs created by Meteos as below.
| Property    | Value                                |
 
+-------------+--------------------------------------+
 
| created_at  | 2016-10-20T02:11:51.778930          |
 
| description | This is a sample experiment          |
 
| id          | 0550a7db-b148-4319-bb35-16a9e4500d4a |
 
| name        | example-experiment                  |
 
| project_id  | 5f011d076a6f4a328989c57ac7b4e501    |
 
| status      | available                            |
 
+-------------+--------------------------------------+
 
  
Meteos creates a experiment using OpenStack Sahara spark plugin.
+
<pre>
User can see a sahara cluster and nova VMs created by Meteos.
+
$ openstack dataprocessing cluster list (or sahara cluster-list)
 +
+------------------+--------------------------------------+-------------+----------------+----------+
 +
| Name            | Id                                  | Plugin name | Plugin version | Status  |
 +
+------------------+--------------------------------------+-------------+----------------+----------+
 +
| cluster-fcc8d055 | 5736d157-ac7c-41de-8aca-78f7afa7e99c | spark       | 1.6.0          | Spawning |
 +
+------------------+--------------------------------------+-------------+----------------+----------+
 +
</pre>
 +
<pre>
 +
$ openstack server list (or nova list)
 +
+--------------------------------------+----------------------------+--------+------------+-------------+------------------+
 +
| ID                                  | Name                      | Status | Task State | Power State | Networks        |
 +
+--------------------------------------+----------------------------+--------+------------+-------------+------------------+
 +
| 48a9f429-7756-4bed-8dd6-6dc6140ef897 | cluster-fcc8d055-master-0  | ACTIVE | -          | Running    | private=10.0.0.5 |
 +
| 88ff2070-dfe8-45da-aa5c-02ac3e9de3b8 | cluster-fcc8d055-workers-0 | ACTIVE | -          | Running    | private=10.0.0.7 |
 +
| a57dfa5d-8b55-47c7-aae7-d5b3c8779787 | cluster-fcc8d055-workers-1 | ACTIVE | -          | Running    | private=10.0.0.4 |
 +
+--------------------------------------+----------------------------+--------+------------+-------------+------------------+
 +
</pre>
 +
 
 +
=== 3. Upload a raw data ===
 +
 
 +
Upload a raw data (in this example past sales figures data) to OpenStack Swift.
  
'''$ sahara cluster-list'''
+
You can use a sample data located in '''python-meteosclient/sample/data/linear_data.txt'''
+------------------+--------------------------------------+--------+------------+
 
| name            | id                                  | status | node_count |
 
+------------------+--------------------------------------+--------+------------+
 
| cluster-0550a7db | 13b04f2e-5605-4b6b-b9fb-1ddf3dd85550 | Active | 3          |
 
+------------------+--------------------------------------+--------+------------+
 
  
'''$ nova list'''
+
Raw data shows "sales figures", "day", "month", "year", "day of week", "parameter which indicates weather", "degree", "humidity" from left.
+--------------------------------------+----------------------------+---------+------------+-------------+-----------------------------------+
 
| ID                                  | Name                      | Status  | Task State | Power State | Networks                          |
 
+--------------------------------------+----------------------------+---------+------------+-------------+-----------------------------------+
 
| f526ec88-9000-4ddd-8f3b-ab60abbf7ca6 | cluster-0550a7db-master-0  | ACTIVE  | -          | Running    | private=10.0.0.140, 192.168.0.99  |
 
| 6812aaa6-430d-4622-acd6-a558e1505e05 | cluster-0550a7db-workers-0 | ACTIVE  | -          | Running    | private=10.0.0.141, 192.168.0.92  |
 
| 825727cf-f115-4d50-af26-99224ec94f8f | cluster-0550a7db-workers-1 | ACTIVE  | -          | Running    | private=10.0.0.139, 192.168.0.100 |
 
+--------------------------------------+----------------------------+---------+------------+-------------+-----------------------------------+
 
  
=== 3. Upload a raw data ===
+
<pre>
 +
$ cd sample/data/
 +
</pre>
 +
<pre>
 +
/sample/data$ head linear_data.txt
 +
4500,1,1,2016,5,0,40,50
 +
8000,2,1,2016,6,1,60,80
 +
9500,3,1,2016,0,2,88,92
 +
5000,4,1,2016,1,3,90,90
 +
0,5,1,2016,2,2,90,80
 +
4500,6,1,2016,3,3,80,90
 +
4000,7,1,2016,4,1,60,80
 +
4500,8,1,2016,5,0,40,50
 +
8000,9,1,2016,6,0,30,50
 +
9500,10,1,2016,0,0,40,50
 +
</pre>
 +
<pre>
 +
/sample/data$ swift upload meteos linear_data.txt
 +
linear_data.txt
 +
</pre>
  
Upload a raw data (sales data) to OpenStack Swift.
+
=== 4. Parse a raw data ===
Raw data shows "sales", "day", "month", "year", "day of week", "parameter which indicates weather", "degree", "humidity" from left.
 
  
'''$ head meteos-test-data.txt'''
+
Parse a raw data to eliminate exception data.
500000,1,10,2016,6,0,68,50
 
550000,2,10,2016,0,1,68,90
 
300000,3,10,2016,1,0,60,55
 
350000,4,10,2016,2,2,58,87
 
0,5,10,2016,3,3,58,60 # a horiday
 
400000,6,10,2016,4,3,60,60
 
330000,7,10,2016,5,2,62,87
 
550000,8,10,2016,6,1,66,92
 
600000,9,10,2016,0,1,55,93
 
330000,10,10,2016,1,0,57,55
 
  
'''$ swift upload meteos meteos-test-data.txt'''
+
In this case, you have to eliminate holiday sales figures because exception data affect the accuracy of prediction model.
meteos-test-data.txt
 
  
=== 4. Download a raw data to experiment ===
+
You can use a sample format located in '''python-meteosclient/sample/json/dataset_parse.json'''
  
Download a raw data from swift to experiment.
+
You can see the head data of parsed dataset by executing "meteos dataset-show <dataset-uuid>" command.
Downloaded data is distributed in HDFS (Hadoop Distributed File System).
 
  
'''$ cat json/download_dataset.json'''
+
<pre>
{
+
$ vim ../python-meteosclient/sample/json/dataset_parse.json
 +
</pre>
 +
<pre>
 +
$ cat sample/json/dataset_parse.json
 +
{
 +
    "source_dataset_url": "swift://meteos/linear_data.txt",
 
     "display_name": "sample-data",
 
     "display_name": "sample-data",
 
     "display_description": "This is a sample dataset",
 
     "display_description": "This is a sample dataset",
     "account": "demo:user01",
+
     "method": "parse",
     "password": "0251c36e80584efd",
+
     "params": [{"method": "filter", "args": "lambda l: l.split(',')[0] != '0'"}],
    "authurl": "http://192.168.0.4:5000/v2.0",
+
    "experiment_id": "fcc8d055-e801-4652-af8c-5aabedbf0286",
     "container_name": "meteos",
+
    "swift_tenant": "demo",
     "object_name": "meteos-test-data.txt",
+
     "swift_username": "demo",
     "experiment_id": "0550a7db-b148-4319-bb35-16a9e4500d4a"
+
     "swift_password": "nova"
}
+
}
 +
</pre>
 +
<pre>
 +
$ meteos dataset-create --json sample/json/dataset_parse.json
 +
+-------------+--------------------------------------+
 +
| Property    | Value                                |
 +
+-------------+--------------------------------------+
 +
| created_at  | 2016-12-15T23:04:11.000000          |
 +
| description | This is a sample dataset            |
 +
| head        | None                                |
 +
| id          | 91d98f6d-a065-431b-b8e0-1b996ac85cec |
 +
| name        | sample-data                         |
 +
| project_id  | 4034bb3cd9324776a68c140fdd18baa4    |
 +
| status      | creating                            |
 +
| stderr      | None                                |
 +
| user_id    | 64ad04e101df40b4b51e5f370a83412c    |
 +
+-------------+--------------------------------------+
 +
</pre>
 +
<pre>
 +
$ meteos dataset-list
 +
+--------------------------------------+-------------+-----------+--------------------------------+
 +
| id                                  | name        | status    | source_dataset_url            |
 +
+--------------------------------------+-------------+-----------+--------------------------------+
 +
| 91d98f6d-a065-431b-b8e0-1b996ac85cec | sample-data | available | swift://meteos/linear_data.txt |
 +
+--------------------------------------+-------------+-----------+--------------------------------+
 +
</pre>
 +
You can see that holiday sales figures has been eliminated.
 +
<pre>
 +
$ meteos dataset-show 91d98f6d-a065-431b-b8e0-1b996ac85cec
 +
+-------------+--------------------------------------+
 +
| Property    | Value                                |
 +
+-------------+--------------------------------------+
 +
| created_at  | 2016-12-15T23:04:11.000000          |
 +
| description | This is a sample dataset            |
 +
| head        | [u'4500,1,1,2016,5,0,40,50',        |
 +
|            | u'8000,2,1,2016,6,1,60,80',          |
 +
|            | u'9500,3,1,2016,0,2,88,92',          |
 +
|            | u'5000,4,1,2016,1,3,90,90',          |
 +
|            | u'4500,6,1,2016,3,3,80,90',          |
 +
|            | u'4000,7,1,2016,4,1,60,80',          |
 +
|            | u'4500,8,1,2016,5,0,40,50',          |
 +
|            | u'8000,9,1,2016,6,0,30,50',          |
 +
|            | u'9500,10,1,2016,0,0,40,50',        |
 +
|            | u'5000,11,1,2016,1,1,60,80']        |
 +
| id          | 91d98f6d-a065-431b-b8e0-1b996ac85cec |
 +
| name        | sample-data                          |
 +
| project_id  | 4034bb3cd9324776a68c140fdd18baa4     |
 +
| status      | available                            |
 +
| stderr      |                                      |
 +
| user_id    | 64ad04e101df40b4b51e5f370a83412c    |
 +
+-------------+--------------------------------------+
 +
</pre>
  
'''$ meteos dataset-download --json json/download_dataset.json'''
+
=== 5. Create a prediction model ===
  
+-------------+--------------------------------------+
+
In this example, User creates a Linear Regression Model from parsed dataset.
| Property    | Value                                |
 
+-------------+--------------------------------------+
 
| created_at  | 2016-10-20T02:17:27.831814          |
 
| description | This is a sample dataset             |
 
| id          | bd134722-22cd-4247-8e20-538933e0975d |
 
| name        | sample-data                          |
 
| project_id  | 5f011d076a6f4a328989c57ac7b4e501    |
 
| status      | available                            |
 
+-------------+--------------------------------------+
 
  
=== 5. Parse a raw data ===
+
Parsed dataset has been already distributed in hdfs of experiment environment.
  
Parse a raw data to enable MLlib (Apache Spark's scalable machine learning library) to handle it.
+
So, you spefity the internal url (internal://<dataset-id>) in source_dataset_url parameter.
Requirement format depends on machine learning algorithms.
 
In this example, convert to a list format using map method and remove unused fields using filter method.
 
  
[[File:Dataset-parse.png]]
+
<pre>
 +
$ vim sample/json/model_linear.json
 +
</pre>
 +
<pre>
 +
$ cat sample/json/model_linear.json
 +
{
 +
    "display_name": "linear-model",
 +
    "display_description": "Sample LinearRegression Model",
 +
    "source_dataset_url": "internal://91d98f6d-a065-431b-b8e0-1b996ac85cec",
 +
    "model_type": "LinearRegression",
 +
    "model_params": "{'numIterations': 200}",
 +
    "experiment_id": "fcc8d055-e801-4652-af8c-5aabedbf0286"
 +
}
 +
</pre>
 +
<pre>
 +
$ meteos model-create --json sample/json/model_linear.json
 +
+-------------+--------------------------------------+
 +
| Property    | Value                                |
 +
+-------------+--------------------------------------+
 +
| created_at  | 2016-12-15T23:09:36.000000          |
 +
| description | Sample LinearRegression Model        |
 +
| id          | 3cf02c2f-f043-49e5-a0df-0dc782868312 |
 +
| name        | linear-model                        |
 +
| params      | eydudW1JdGVyYXRpb25zJzogMjAwfQ==    |
 +
| project_id  | 4034bb3cd9324776a68c140fdd18baa4    |
 +
| status      | creating                            |
 +
| stderr      | None                                |
 +
| stdout      | None                                |
 +
| type        | LinearRegression                    |
 +
| user_id    | 64ad04e101df40b4b51e5f370a83412c    |
 +
+-------------+--------------------------------------+
 +
</pre>
 +
<pre>
 +
$ meteos model-list
 +
+--------------------------------------+--------------+-----------+------------------+-------------------------------------------------+
 +
| id                                  | name        | status    | type            | source_dataset_url                              |
 +
+--------------------------------------+--------------+-----------+------------------+-------------------------------------------------+
 +
| 3cf02c2f-f043-49e5-a0df-0dc782868312 | linear-model | available | LinearRegression | internal://91d98f6d-a065-431b-b8e0-1b996ac85cec |
 +
+--------------------------------------+--------------+-----------+------------------+-------------------------------------------------+
 +
</pre>
  
'''$ cat json/parse_dataset.json'''
+
=== 6. Predict ===
{
 
    "id": "bd134722-22cd-4247-8e20-538933e0975d",
 
    "method": "parse",
 
    "params": ["method": "map", "ars": "lambda l: l.split(',')",
 
              "method": "filter", "ars": "lambda l: l[0]! = '0'"],
 
    "experiment_id": "0550a7db-b148-4319-bb35-16a9e4500d4a"
 
}
 
  
'''$ meteos dataset-parse --json json/parse_dataset.json'''
+
Create a learning job predicting a Sales Figures.
  
=== 6. Create a prediction model ===
+
Specify the input value as "args" parameter.
  
In this example, User creates a Linear Regression Model.
+
Retrieve a predicted data as a stdout of job execution.
  
'''$ cat json/create_model.json'''
+
<pre>
{
+
$ vim sample/json/learning.json
     "display_name": "sample-lr-model",
+
</pre>
     "display_description": "This is a sample model",
+
<pre>
     "dataset_id": "bd134722-22cd-4247-8e20-538933e0975d",
+
$ cat sample/json/learning.json
     "method": "LinearRegression",
+
{
     "args": "{'numIterations': 10, 'desired_output':0}",
+
     "display_name": "example-learning-job",
    "experiment_id": "c08027ab-2ea5-4b57-840c-563908cfca46"
+
     "display_description": "This is a sample job",
  }
+
     "model_id": "3cf02c2f-f043-49e5-a0df-0dc782868312",
 +
     "method": "predict",
 +
     "args": "1,7,2016,5,0,60,80"
 +
}
 +
</pre>
 +
<pre>
 +
$ meteos learning-create --json sample/json/learning.json
 +
+-------------+--------------------------------------+
 +
| Property    | Value                                |
 +
+-------------+--------------------------------------+
 +
| args        | MSw3LDIwMTYsNSwwLDYwLDgw            |
 +
| created_at  | 2016-12-15T23:13:29.000000          |
 +
| description | This is a sample job                |
 +
| id          | ffcd3ae6-8b53-437e-94e2-3aabde741cb0 |
 +
| method      | predict                              |
 +
| name        | example-learning-job                |
 +
| project_id | 4034bb3cd9324776a68c140fdd18baa4    |
 +
| status      | creating                            |
 +
| stderr      | None                                |
 +
| stdout      | None                                |
 +
| user_id    | 64ad04e101df40b4b51e5f370a83412c    |
 +
+-------------+--------------------------------------+
 +
</pre>
 +
<pre>
 +
$ meteos learning-list
 +
+--------------------------------------+----------------------+-----------+--------------------+---------------+
 +
| id                                  | name                | status    | args              | stdout        |
 +
+--------------------------------------+----------------------+-----------+--------------------+---------------+
 +
| ffcd3ae6-8b53-437e-94e2-3aabde741cb0 | example-learning-job | available | 1,7,2016,5,0,60,80 | 4048.18352502 |
 +
+--------------------------------------+----------------------+-----------+--------------------+---------------+
 +
</pre>
  
'''$ meteos model-create --json json/create_model.json'''
+
=== 7. Online Prediction ===
  
+-------------+--------------------------------------+
+
You can load a Prediction Model in advance for online prediction by using "meteos-load" command.
| Property    | Value                                |
 
+-------------+--------------------------------------+
 
| created_at  | 2016-10-20T02:17:27.831814          |
 
| description | This is a sample model              |
 
| id          | c48f5dba-45be-4165-9825-f4564fecebcd |
 
| name        | sample-lr-mode                      |
 
| project_id  | 5f011d076a6f4a328989c57ac7b4e501    |
 
| status      | available                            |
 
+-------------+--------------------------------------+
 
  
=== 7. Predict ===
+
In online prediction, user can retrieve a predicted data immediately.
  
Create a predict job.
+
''' Note: Meteos can not load multiple models at the same time. So, you have to unload a model before loading another model. '''
  
'''$ cat json/predict_data.json'''
+
<pre>
 +
$ meteos model-load 3cf02c2f-f043-49e5-a0df-0dc782868312
 +
</pre>
 +
<pre>
 +
$ meteos model-list
 +
+--------------------------------------+--------------+------------+------------------+-------------------------------------------------+
 +
| id                                  | name        | status    | type            | source_dataset_url                              |
 +
+--------------------------------------+--------------+------------+------------------+-------------------------------------------------+
 +
| 3cf02c2f-f043-49e5-a0df-0dc782868312 | linear-model | activating | LinearRegression | internal://91d98f6d-a065-431b-b8e0-1b996ac85cec |
 +
+--------------------------------------+--------------+------------+------------------+-------------------------------------------------+
 +
</pre>
  
{
+
Status is set to "active" when loading is complete.
    "display_name": "predict job",
 
    "display_description": "This is a sample job",
 
    "model_id": "bd134722-22cd-4247-8e20-538933e0975d",
 
    "method": "predict",
 
    "args": "11,10,2016,2,0,57,58",
 
    "experiment_id": "c08027ab-2ea5-4b57-840c-563908cfca46"
 
}
 
  
'''$ meteos job-create --json json/predict_data.json'''
+
<pre>
 +
$ meteos model-list
 +
+--------------------------------------+--------------+--------+------------------+-------------------------------------------------+
 +
| id                                  | name        | status | type            | source_dataset_url                              |
 +
+--------------------------------------+--------------+--------+------------------+-------------------------------------------------+
 +
| 3cf02c2f-f043-49e5-a0df-0dc782868312 | linear-model | active | LinearRegression | internal://91d98f6d-a065-431b-b8e0-1b996ac85cec |
 +
+--------------------------------------+--------------+--------+------------------+-------------------------------------------------+
 +
</pre>
  
+-------------+--------------------------------------+
+
You can get a predicted data as a response of REST API .
| Property    | Value                                |
 
+-------------+--------------------------------------+
 
| created_at  | 2016-10-20T02:17:37.644234          |
 
| description | This is a sample job                |
 
| id          | c38b9c22-d72c-4255-8236-7e319d351fad |
 
| name        | predict_job                          |
 
| project_id  | 5f011d076a6f4a328989c57ac7b4e501    |
 
| status      | executing                            |
 
+-------------+--------------------------------------+
 
 
 
Retrieve a predicted data as a stdout of job execution.
 
  
'''$ meteos job-show c38b9c22-d72c-4255-8236-7e319d351fad'''
+
<pre>
 +
$ meteos learning-create --json sample/json/learning.json
 +
+-------------+--------------------------------------+
 +
| Property    | Value                                |
 +
+-------------+--------------------------------------+
 +
| args        | MSw3LDIwMTYsNSwwLDYwLDgw            |
 +
| created_at  | 2016-12-15T23:13:29.000000          |
 +
| description | This is a sample job                |
 +
| id          | ffcd3ae6-8b53-437e-94e2-3aabde741cb0 |
 +
| method      | predict                              |
 +
| name        | example-learning-job                 |
 +
| project_id  | 4034bb3cd9324776a68c140fdd18baa4    |
 +
| status      | available                            |
 +
| stderr      | None                                |
 +
| stdout      | 4048.18352502                        |
 +
| user_id    | 64ad04e101df40b4b51e5f370a83412c    |
 +
+-------------+--------------------------------------+
 +
</pre>
  
+----------------------------+-------------------------------------------------+
+
<pre>
| Property                  | Value                                          |
+
$ meteos model-unload 3cf02c2f-f043-49e5-a0df-0dc782868312
+----------------------------+-------------------------------------------------+
+
</pre>
| stdout                    | Value : (325944.477851)                        |
 
| stderr                    |                                                |
 
+----------------------------+-------------------------------------------------+
 

Latest revision as of 06:45, 10 January 2017

Predict a Sales Figures using Meteos

In this example, you create a prediction model which predict sales by using Linear Regression.

Linear Regression is one of the algorithms in supervised learning.

Usecase.png

1. Create a experiment template

Create template of experiment. Experiment is a workspace of Machine Learning.

You have to confirm a glance image id of meteos image, and a neutron network id before creating a template.

You can use a format located in python-meteosclient/sample/json/template.json

$ glance image-list | grep meteos
| a6b7de0b-10ff-462c-9c86-25c8a5622a57 | meteos                          |
$ neutron net-list | grep public
| 4222b557-6d9f-405c-b1ff-0f454d2f35bf | public  | 1f979ae3-d6b7-4d03-ba0f-9d9112581783             |
$ vim sample/json/template.json
$ cat sample/json/template.json
{
    "display_name": "example-template",
    "display_description": "This is a sample template of experiment",
    "image_id" : "a6b7de0b-10ff-462c-9c86-25c8a5622a57",
    "master_nodes_num": 1,
    "master_flavor_id": "4",
    "worker_nodes_num": 2,
    "worker_flavor_id": "2",
    "spark_version": "1.6.0",
    "floating_ip_pool": "4222b557-6d9f-405c-b1ff-0f454d2f35bf"
}
$ meteos template-create --json sample/json/template.json
+---------------+-----------------------------------------+
| Property      | Value                                   |
+---------------+-----------------------------------------+
| cluster_id    | None                                    |
| created_at    | 2016-12-15T22:55:03.000000              |
| description   | This is a sample template of experiment |
| id            | d3180a78-74cc-432d-9e9d-68640b18abae    |
| master_flavor | 4                                       |
| master_nodes  | 1                                       |
| name          | example-template                        |
| project_id    | 4034bb3cd9324776a68c140fdd18baa4        |
| spark_version | 1.6.0                                   |
| status        | available                               |
| user_id       | 64ad04e101df40b4b51e5f370a83412c        |
| worker_flavor | 2                                       |
| worker_nodes  | 2                                       |
+---------------+-----------------------------------------+

2. Create a experiment from template

Create a experiment by using template created in the above step. You have to confirm a neutron private network id and create keypair before creating a template.

You can use a format located in python-meteosclient/sample/json/experiment.json

$ nova keypair-add key1 > ~/key1.pem && chmod 600 ~/key1.pem
$ neutron net-list | grep private
| e4fcc49c-48e5-48f8-9599-bb5eba1339c9 | private | e15c24a5-dfdd-4428-b27d-9827b35600c0 10.0.0.0/26 |
$ vim sample/json/experiment.json
$ cat sample/json/experiment.json
{
    "display_name": "example-experiment",
    "display_description": "This is a sample experiment",
    "key_name": "key1",
    "neutron_management_network": "e4fcc49c-48e5-48f8-9599-bb5eba1339c9",
    "template_id": "d3180a78-74cc-432d-9e9d-68640b18abae"
}
$ meteos experiment-create --json sample/json/experiment.json
+--------------------+--------------------------------------+
| Property           | Value                                |
+--------------------+--------------------------------------+
| created_at         | 2016-12-15T22:56:51.000000           |
| description        | This is a sample experiment          |
| id                 | fcc8d055-e801-4652-af8c-5aabedbf0286 |
| key_name           | key1                                 |
| management_network | e4fcc49c-48e5-48f8-9599-bb5eba1339c9 |
| name               | example-experiment                   |
| project_id         | 4034bb3cd9324776a68c140fdd18baa4     |
| status             | creating                             |
| user_id            | 64ad04e101df40b4b51e5f370a83412c     |
+--------------------+--------------------------------------+

Meteos creates a experiment using OpenStack Sahara spark plugin.

You can see a sahara cluster and nova VMs created by Meteos as below.

$ openstack dataprocessing cluster list (or sahara cluster-list)
+------------------+--------------------------------------+-------------+----------------+----------+
| Name             | Id                                   | Plugin name | Plugin version | Status   |
+------------------+--------------------------------------+-------------+----------------+----------+
| cluster-fcc8d055 | 5736d157-ac7c-41de-8aca-78f7afa7e99c | spark       | 1.6.0          | Spawning |
+------------------+--------------------------------------+-------------+----------------+----------+
$ openstack server list (or nova list)
+--------------------------------------+----------------------------+--------+------------+-------------+------------------+
| ID                                   | Name                       | Status | Task State | Power State | Networks         |
+--------------------------------------+----------------------------+--------+------------+-------------+------------------+
| 48a9f429-7756-4bed-8dd6-6dc6140ef897 | cluster-fcc8d055-master-0  | ACTIVE | -          | Running     | private=10.0.0.5 |
| 88ff2070-dfe8-45da-aa5c-02ac3e9de3b8 | cluster-fcc8d055-workers-0 | ACTIVE | -          | Running     | private=10.0.0.7 |
| a57dfa5d-8b55-47c7-aae7-d5b3c8779787 | cluster-fcc8d055-workers-1 | ACTIVE | -          | Running     | private=10.0.0.4 |
+--------------------------------------+----------------------------+--------+------------+-------------+------------------+

3. Upload a raw data

Upload a raw data (in this example past sales figures data) to OpenStack Swift.

You can use a sample data located in python-meteosclient/sample/data/linear_data.txt

Raw data shows "sales figures", "day", "month", "year", "day of week", "parameter which indicates weather", "degree", "humidity" from left.

$ cd sample/data/
/sample/data$ head linear_data.txt
4500,1,1,2016,5,0,40,50
8000,2,1,2016,6,1,60,80
9500,3,1,2016,0,2,88,92
5000,4,1,2016,1,3,90,90
0,5,1,2016,2,2,90,80
4500,6,1,2016,3,3,80,90
4000,7,1,2016,4,1,60,80
4500,8,1,2016,5,0,40,50
8000,9,1,2016,6,0,30,50
9500,10,1,2016,0,0,40,50
/sample/data$ swift upload meteos linear_data.txt
linear_data.txt

4. Parse a raw data

Parse a raw data to eliminate exception data.

In this case, you have to eliminate holiday sales figures because exception data affect the accuracy of prediction model.

You can use a sample format located in python-meteosclient/sample/json/dataset_parse.json

You can see the head data of parsed dataset by executing "meteos dataset-show <dataset-uuid>" command.

$ vim ../python-meteosclient/sample/json/dataset_parse.json
$ cat sample/json/dataset_parse.json
{
    "source_dataset_url": "swift://meteos/linear_data.txt",
    "display_name": "sample-data",
    "display_description": "This is a sample dataset",
    "method": "parse",
    "params": [{"method": "filter", "args": "lambda l: l.split(',')[0] != '0'"}],
    "experiment_id": "fcc8d055-e801-4652-af8c-5aabedbf0286",
    "swift_tenant": "demo",
    "swift_username": "demo",
    "swift_password": "nova"
}
$ meteos dataset-create --json sample/json/dataset_parse.json
+-------------+--------------------------------------+
| Property    | Value                                |
+-------------+--------------------------------------+
| created_at  | 2016-12-15T23:04:11.000000           |
| description | This is a sample dataset             |
| head        | None                                 |
| id          | 91d98f6d-a065-431b-b8e0-1b996ac85cec |
| name        | sample-data                          |
| project_id  | 4034bb3cd9324776a68c140fdd18baa4     |
| status      | creating                             |
| stderr      | None                                 |
| user_id     | 64ad04e101df40b4b51e5f370a83412c     |
+-------------+--------------------------------------+
$ meteos dataset-list
+--------------------------------------+-------------+-----------+--------------------------------+
| id                                   | name        | status    | source_dataset_url             |
+--------------------------------------+-------------+-----------+--------------------------------+
| 91d98f6d-a065-431b-b8e0-1b996ac85cec | sample-data | available | swift://meteos/linear_data.txt |
+--------------------------------------+-------------+-----------+--------------------------------+

You can see that holiday sales figures has been eliminated.

$ meteos dataset-show 91d98f6d-a065-431b-b8e0-1b996ac85cec
+-------------+--------------------------------------+
| Property    | Value                                |
+-------------+--------------------------------------+
| created_at  | 2016-12-15T23:04:11.000000           |
| description | This is a sample dataset             |
| head        | [u'4500,1,1,2016,5,0,40,50',         |
|             | u'8000,2,1,2016,6,1,60,80',          |
|             | u'9500,3,1,2016,0,2,88,92',          |
|             | u'5000,4,1,2016,1,3,90,90',          |
|             | u'4500,6,1,2016,3,3,80,90',          |
|             | u'4000,7,1,2016,4,1,60,80',          |
|             | u'4500,8,1,2016,5,0,40,50',          |
|             | u'8000,9,1,2016,6,0,30,50',          |
|             | u'9500,10,1,2016,0,0,40,50',         |
|             | u'5000,11,1,2016,1,1,60,80']         |
| id          | 91d98f6d-a065-431b-b8e0-1b996ac85cec |
| name        | sample-data                          |
| project_id  | 4034bb3cd9324776a68c140fdd18baa4     |
| status      | available                            |
| stderr      |                                      |
| user_id     | 64ad04e101df40b4b51e5f370a83412c     |
+-------------+--------------------------------------+

5. Create a prediction model

In this example, User creates a Linear Regression Model from parsed dataset.

Parsed dataset has been already distributed in hdfs of experiment environment.

So, you spefity the internal url (internal://<dataset-id>) in source_dataset_url parameter.

$ vim sample/json/model_linear.json
$ cat sample/json/model_linear.json
{
    "display_name": "linear-model",
    "display_description": "Sample LinearRegression Model",
    "source_dataset_url": "internal://91d98f6d-a065-431b-b8e0-1b996ac85cec",
    "model_type": "LinearRegression",
    "model_params": "{'numIterations': 200}",
    "experiment_id": "fcc8d055-e801-4652-af8c-5aabedbf0286"
}
$ meteos model-create --json sample/json/model_linear.json
+-------------+--------------------------------------+
| Property    | Value                                |
+-------------+--------------------------------------+
| created_at  | 2016-12-15T23:09:36.000000           |
| description | Sample LinearRegression Model        |
| id          | 3cf02c2f-f043-49e5-a0df-0dc782868312 |
| name        | linear-model                         |
| params      | eydudW1JdGVyYXRpb25zJzogMjAwfQ==     |
| project_id  | 4034bb3cd9324776a68c140fdd18baa4     |
| status      | creating                             |
| stderr      | None                                 |
| stdout      | None                                 |
| type        | LinearRegression                     |
| user_id     | 64ad04e101df40b4b51e5f370a83412c     |
+-------------+--------------------------------------+
$ meteos model-list
+--------------------------------------+--------------+-----------+------------------+-------------------------------------------------+
| id                                   | name         | status    | type             | source_dataset_url                              |
+--------------------------------------+--------------+-----------+------------------+-------------------------------------------------+
| 3cf02c2f-f043-49e5-a0df-0dc782868312 | linear-model | available | LinearRegression | internal://91d98f6d-a065-431b-b8e0-1b996ac85cec |
+--------------------------------------+--------------+-----------+------------------+-------------------------------------------------+

6. Predict

Create a learning job predicting a Sales Figures.

Specify the input value as "args" parameter.

Retrieve a predicted data as a stdout of job execution.

$ vim sample/json/learning.json
$ cat sample/json/learning.json
{
    "display_name": "example-learning-job",
    "display_description": "This is a sample job",
    "model_id": "3cf02c2f-f043-49e5-a0df-0dc782868312",
    "method": "predict",
    "args": "1,7,2016,5,0,60,80"
}
$ meteos learning-create --json sample/json/learning.json
+-------------+--------------------------------------+
| Property    | Value                                |
+-------------+--------------------------------------+
| args        | MSw3LDIwMTYsNSwwLDYwLDgw             |
| created_at  | 2016-12-15T23:13:29.000000           |
| description | This is a sample job                 |
| id          | ffcd3ae6-8b53-437e-94e2-3aabde741cb0 |
| method      | predict                              |
| name        | example-learning-job                 |
| project_id  | 4034bb3cd9324776a68c140fdd18baa4     |
| status      | creating                             |
| stderr      | None                                 |
| stdout      | None                                 |
| user_id     | 64ad04e101df40b4b51e5f370a83412c     |
+-------------+--------------------------------------+
$ meteos learning-list
+--------------------------------------+----------------------+-----------+--------------------+---------------+
| id                                   | name                 | status    | args               | stdout        |
+--------------------------------------+----------------------+-----------+--------------------+---------------+
| ffcd3ae6-8b53-437e-94e2-3aabde741cb0 | example-learning-job | available | 1,7,2016,5,0,60,80 | 4048.18352502 |
+--------------------------------------+----------------------+-----------+--------------------+---------------+

7. Online Prediction

You can load a Prediction Model in advance for online prediction by using "meteos-load" command.

In online prediction, user can retrieve a predicted data immediately.

Note: Meteos can not load multiple models at the same time. So, you have to unload a model before loading another model.

$ meteos model-load 3cf02c2f-f043-49e5-a0df-0dc782868312
$ meteos model-list
+--------------------------------------+--------------+------------+------------------+-------------------------------------------------+
| id                                   | name         | status     | type             | source_dataset_url                              |
+--------------------------------------+--------------+------------+------------------+-------------------------------------------------+
| 3cf02c2f-f043-49e5-a0df-0dc782868312 | linear-model | activating | LinearRegression | internal://91d98f6d-a065-431b-b8e0-1b996ac85cec |
+--------------------------------------+--------------+------------+------------------+-------------------------------------------------+

Status is set to "active" when loading is complete.

$ meteos model-list
+--------------------------------------+--------------+--------+------------------+-------------------------------------------------+
| id                                   | name         | status | type             | source_dataset_url                              |
+--------------------------------------+--------------+--------+------------------+-------------------------------------------------+
| 3cf02c2f-f043-49e5-a0df-0dc782868312 | linear-model | active | LinearRegression | internal://91d98f6d-a065-431b-b8e0-1b996ac85cec |
+--------------------------------------+--------------+--------+------------------+-------------------------------------------------+

You can get a predicted data as a response of REST API .

$ meteos learning-create --json sample/json/learning.json
+-------------+--------------------------------------+
| Property    | Value                                |
+-------------+--------------------------------------+
| args        | MSw3LDIwMTYsNSwwLDYwLDgw             |
| created_at  | 2016-12-15T23:13:29.000000           |
| description | This is a sample job                 |
| id          | ffcd3ae6-8b53-437e-94e2-3aabde741cb0 |
| method      | predict                              |
| name        | example-learning-job                 |
| project_id  | 4034bb3cd9324776a68c140fdd18baa4     |
| status      | available                            |
| stderr      | None                                 |
| stdout      | 4048.18352502                        |
| user_id     | 64ad04e101df40b4b51e5f370a83412c     |
+-------------+--------------------------------------+
$ meteos model-unload 3cf02c2f-f043-49e5-a0df-0dc782868312