Models MaxModel


class MaxModel

Entity MaxModel

Attributes

last_read_date Read-only property - Last time this model’s data was accessed.
name Set or get the name of the model object.
status Read-only property - Current model life cycle status.

Methods

__init__(self[, name, _info]) Create a ‘new’ instance of Moving Average with Explanatory Variables (MAX) model.
predict(self, frame, timeseries_column, x_columns) [ALPHA] New frame with column of predicted y values
publish(self) [ALPHA] Creates a tar file that will be used as input to the scoring engine
train(self, frame, timeseries_column, x_columns, q, xreg_max_lag[, ...]) [ALPHA] <Missing Doc>
__init__(self, name=None)

Create a ‘new’ instance of Moving Average with Explanatory Variables (MAX) model.

Parameters:

name : unicode (default=None)

User supplied name.

Returns:

: Model

A new instance of MAXModel

Examples

Consider the following model trained and tested on the sample data set in frame ‘frame’. The frame has five columns where “CO_GT” is the time series value and “C6H6_GT”, “PT08_S2_NMHC” and “T” are exogenous inputs.

CO_GT - True hourly averaged concentration CO in mg/m^3 C6H6_GT - True hourly averaged Benzene concentration in microg/m^3 PT08_S2_NMHC - Titania hourly averaged sensor response (nominally NMHC targeted) T - Temperature in C

Data from Lichman, M. (2013). UCI Machine Learning Repository [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California, School of Information and Computer Science.

>>> frame.inspect(columns=["CO_GT","C6H6_GT","PT08_S2_NMHC","T"])
[#]  CO_GT  C6H6_GT  PT08_S2_NMHC  T
=======================================
[0]    2.6     11.9        1046.0  13.6
[1]    2.0      9.4         955.0  13.3
[2]    2.2      9.0         939.0  11.9
[3]    2.2      9.2         948.0  11.0
[4]    1.6      6.5         836.0  11.2
[5]    1.2      4.7         750.0  11.2
[6]    1.2      3.6         690.0  11.3
[7]    1.0      3.3         672.0  10.7
[8]    0.9      2.3         609.0  10.7
[9]    0.6      1.7         561.0  10.3
>>> model = ta.MaxModel()
[===Job Progress===]
>>> train_output = model.train(frame, "CO_GT", ["C6H6_GT","PT08_S2_NMHC","T"],  3, 0, True, False)
[===Job Progress===]
>>> train_output
{u'c': -0.015810846625808755, u'ar': [], u'ma': [-0.006660356395570438, -0.005292835493585051, -0.06161070314834268], u'xreg': [-16.614401259906035, 0.4329581171119422, 0.41537792101978993]}
>>> test_frame = ta.Frame(ta.UploadRows([[3.9, 19.3, 1277.0, 15.1],
...                                      [3.7, 18.2, 1246.0, 14.4],
...                                      [6.6, 32.6, 1610.0, 12.9],
...                                      [4.4, 20.1, 1299.0, 12.1],
...                                      [3.5, 14.3, 1127.0, 11.0],
...                                      [5.4, 21.8, 1346.0, 9.7],
...                                      [2.7, 9.6, 964.0, 9.5],
...                                      [1.9, 7.4, 873.0, 9.1],
...                                      [1.6, 5.4, 782.0, 8.8],
...                                      [1.7, 5.4, 783.0, 7.8]],
...                                      schema=schema))
-etc-
>>> predicted_frame = model.predict(test_frame, "CO_GT", ["C6H6_GT","PT08_S2_NMHC","T"])
[===Job Progress===]
>>> predicted_frame.column_names
[u'CO_GT', u'C6H6_GT', u'PT08_S2_NMHC', u'T', u'predicted_y']
>>> predicted_frame.inspect(columns=("CO_GT","predicted_y"))
[#]  CO_GT  predicted_y
==========================
[0]    3.9  0.155146460184
[1]    3.7   6.40639271956
[2]    6.6   5.98144206268
[3]    4.4   5.35837518116
[4]    3.5   5.02607284434
[5]    5.4   4.56915713122
[6]    2.7   4.02916583389
[7]    1.9   3.94609024969
[8]    1.6   3.77993908128
[9]    1.7   3.65532570497
>>> model.publish()
[===Job Progress===]

Take the path to the published model and run it in the Scoring Engine:

>>> import requests
>>> headers = {'Content-type': 'application/json', 'Accept': 'application/json,text/plain'}

Post a request to get the metadata about the model

>>> r = requests.get('http://mymodel.demotrustedanalytics.com/v2/metadata')
>>> r.text
u'{"model_details":{"model_type":"MAX Model","model_class":"com.cloudera.sparkts.models.ARIMAXModel","model_reader":"org.trustedanalytics.atk.scoring.models.MAXModelReaderPlugin","custom_values":{}},"input":[{"name":"y","value":"Array[Double]"},{"name":"x_values","value":"Array[Double]"}],"output":[{"name":"y","value":"Array[Double]"},{"name":"x_values","value":"Array[Double]"},{"name":"score","value":"Array[Double]"}]}'

The MAX model only supports version 2 of the scoring engine. In the following example, we are using the MAX model that was trained and published in the example above. To keep things simple, we just send the first three rows of ‘y’ values (CO_GT) and the corresponding ‘x_values’ (C6H6_GT,PT08_S2_NMHC,T).

>>> r = requests.post('http://mymodel.demotrustedanalytics.com/v2/score',json={"records":[{"y":[3.9,3.7,6.6],"x_values":[19.3,18.2,32.6,1277.0,1246.0,1610.0,15.1,14.4,12.9]}]})

The ‘score’ value contains an array of predicted y values.

>>> r.text
u'{"data":[{"y":[3.9,3.7,6.6],"x_values":[19.3,18.2,32.6,1277.0,1246.0,1610.0,15.1,14.4,12.9],"score":[0.155146460184, 6.40639271956, 5.98144206268]}]}'