-from __future__ import absolute_import
+
+ Source code for exponential_smoothing
+from __future__ import absolute_import
import sys, os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.append(BASE_DIR)
-from PMML44 import *
-from datetime import datetime
+from PMML44 import *
+from datetime import datetime
import metadata
import warnings
-from enums import *
+from base.constants import *
-class ExponentialSmoothingToPMML:
-
"""
+
[docs]class ExponentialSmoothingToPMML:
+
"""
Write a PMML file using model-object, model-parameters and time series data. Models are built using Statsmodels.
Parameters:
@@ -193,10 +101,10 @@
Source code for ExponentialSmoothing
description : string (optional)
Description of the model
"""
- def __init__(self, results_obj=None, pmml_file_name="from_ExponentialSmoothing.pmml", model_name=None, description=None):
+ def __init__(self, results_obj=None, pmml_file_name="from_ExponentialSmoothing.pmml", model_name=None, description=None):
def get_time_value_objs():
- """
+ """
Does not have time attribute
Parameters:
@@ -218,18 +126,18 @@ Source code for ExponentialSmoothing
pmml_data_type = None
pmml_op_type = 'continuous'
if str(series_obj.dtype) in ['datetime64[ns]', 'datetime64[ns, tz]', 'timedelta[ns]']:
- pmml_data_type = DATATYPE.DATETIME.value
+ pmml_data_type = DATATYPE.DATETIME
elif str(series_obj.dtype) == 'float32':
- pmml_data_type = DATATYPE.FLOAT.value
+ pmml_data_type = DATATYPE.FLOAT
elif str(series_obj.dtype) == 'float64':
- pmml_data_type = DATATYPE.DOUBLE.value
+ pmml_data_type = DATATYPE.DOUBLE
elif str(series_obj.dtype) in ['int64', 'int32']:
- pmml_data_type = DATATYPE.INTEGER.value
-
+ pmml_data_type = DATATYPE.INTEGER
+
return pmml_data_type, pmml_op_type
def get_data_field_objs():
- """
+ """
Create a list with instances of DataField
"""
data_field_objs = list()
@@ -247,7 +155,7 @@ Source code for ExponentialSmoothing
return data_field_objs
def get_mining_field_objs():
- """
+ """
Create a list with instances of MiningField
"""
mining_field_objs = list()
@@ -258,70 +166,72 @@ Source code for ExponentialSmoothing
else:
ts_name = 'input'
idx_name = results_obj.data.orig_endog.index.name
- idx_usage_type = FIELD_USAGE_TYPE.ORDER.value
+ idx_usage_type = FIELD_USAGE_TYPE.ORDER
mining_field_objs.append(MiningField(name=idx_name, usageType=idx_usage_type))
- ts_usage_type = FIELD_USAGE_TYPE.TARGET.value
+ ts_usage_type = FIELD_USAGE_TYPE.TARGET
mining_field_objs.append(MiningField(name=ts_name, usageType=ts_usage_type))
return mining_field_objs
n_samples = results_obj.model.nobs
n_columns = 1 # because we are dealing with Series object
- function_name = MINING_FUNCTION.TIMESERIES.value
- best_fit = TIMESERIES_ALGORITHM.EXPONENTIAL_SMOOTHING.value
+ function_name = MINING_FUNCTION.TIMESERIES
+ best_fit = TIMESERIES_ALGORITHM.EXPONENTIAL_SMOOTHING
extension_objs = list()
alpha = results_obj.params['smoothing_level'] # alpha is smoothing parameter for level
level_smooth_val = results_obj.level[-1] # smoothed level at last time-index
initial_level = results_obj.params['initial_level']
# extension_objs.append(Extension(name='initialLevel', value=initial_level))
import numpy as np
- if np.isnan(results_obj.params['smoothing_slope']):
+ gamma=results_obj.params.get('smoothing_slope',results_obj.params.get('smoothing_trend', None)) # gamma is smoothing parameter for trend
+ if np.isnan(gamma):
gamma = None
- else:
- gamma = results_obj.params['smoothing_slope'] # gamma is smoothing parameter for trend
+ phi=results_obj.params.get('damping_slope',results_obj.params.get('damping_trend', None)) # damping parameter; which is applied on trend/slope
+ if np.isnan(phi):
+ phi = 1
if np.isnan(results_obj.params['smoothing_seasonal']):
delta = None
else:
delta = results_obj.params['smoothing_seasonal'] # delta is smoothing parameter for seasonality
- if np.isnan(results_obj.params['damping_slope']):
- phi = 1
- else:
- phi = results_obj.params['damping_slope'] # damping parameter; which is applied on trend/slope
if results_obj.model.trend: # model_obj.trend can take values in {'add', 'mul', None}
- trend_smooth_val = results_obj.slope[-1]
- initial_trend = results_obj.params['initial_slope']
+ if hasattr(results_obj, 'slope'):
+ trend_smooth_val = results_obj.slope[-1]
+ else:
+ trend_smooth_val = results_obj.trend[-1]
+ initial_trend = results_obj.params.get('initial_slope',results_obj.params.get('initial_trend', None))
if results_obj.model.trend == 'add':
- if results_obj.model.damped:
- trend_type = EXPONENTIAL_SMOOTHING_TREND.DAMPED_ADDITIVE.value
+ if getattr(results_obj.model, 'damped', getattr(results_obj.model, 'damped_trend', None)):
+ trend_type = EXPONENTIAL_SMOOTHING_TREND.DAMPED_ADDITIVE
else:
- trend_type = EXPONENTIAL_SMOOTHING_TREND.ADDITIVE.value
+ trend_type = EXPONENTIAL_SMOOTHING_TREND.ADDITIVE
else: # model_obj.trend == 'mul':
- if results_obj.model.damped:
- trend_type = EXPONENTIAL_SMOOTHING_TREND.DAMPED_MULTIPLICATIVE.value
+ if getattr(results_obj.model, 'damped', getattr(results_obj.model, 'damped_trend', None)):
+ trend_type = EXPONENTIAL_SMOOTHING_TREND.DAMPED_MULTIPLICATIVE
else:
- trend_type = EXPONENTIAL_SMOOTHING_TREND.MULTIPLICATIVE.value
+ trend_type = EXPONENTIAL_SMOOTHING_TREND.MULTIPLICATIVE
trend_obj = Trend_ExpoSmooth(trend=trend_type, gamma=gamma, phi=phi, smoothedValue=trend_smooth_val)
# extension_objs.append(Extension(name='initialTrend', value=initial_trend))
else:
trend_obj = None
if results_obj.model.seasonal: # model_obj.seasonal can take values in {'add', 'mul', None}
period = results_obj.model.seasonal_periods
- initial_seasons = ArrayType(n=period, type_ = ARRAY_TYPE.REAL.value)
+ initial_seasons = ArrayType(n=period, type_ = ARRAY_TYPE.REAL)
content_value = ' '.join([str(i) for i in results_obj.params['initial_seasons']])
initial_seasons.content_[0].value = content_value
if results_obj.model.seasonal == 'add':
- seasonal_type = EXPONENTIAL_SMOOTHING_SEASONALITY.ADDITIVE.value
+ seasonal_type = EXPONENTIAL_SMOOTHING_SEASONALITY.ADDITIVE
else: # model_obj.seasonal == 'mul':
- seasonal_type = EXPONENTIAL_SMOOTHING_SEASONALITY.MULTIPLICATIVE.value
+ seasonal_type = EXPONENTIAL_SMOOTHING_SEASONALITY.MULTIPLICATIVE
season_obj = Seasonality_ExpoSmooth(type_=seasonal_type, period=period, delta=delta,
Array=initial_seasons)
else:
season_obj = None
pmml = PMML(
- version='4.4',
+ version=PMML_SCHEMA.VERSION,
Header=Header(
- copyright="Copyright (c) 2018 Software AG", description=description if description else "Exponential Smoothing Model",
+ copyright=HEADER_INFO.COPYRIGHT,
+ description=description if description else HEADER_INFO.DEFAULT_DESCRIPTION,
Timestamp=Timestamp(datetime.now()),
- Application=Application(name="Nyoka",version=metadata.__version__)
+ Application=Application(name=HEADER_INFO.APPLICATION_NAME,version=HEADER_INFO.APPLICATION_VERSION)
),
DataDictionary=DataDictionary(numberOfFields=n_columns, DataField=get_data_field_objs()),
TimeSeriesModel=[TimeSeriesModel(
@@ -329,7 +239,7 @@ Source code for ExponentialSmoothing
functionName=function_name, bestFit=best_fit, isScorable=True,
MiningSchema=MiningSchema(MiningField=get_mining_field_objs()),
TimeSeries=[TimeSeries(
- usage=TIMESERIES_USAGE.ORIGINAL.value, startTime=0, endTime=n_samples - 1, interpolationMethod='none',
+ usage=TIMESERIES_USAGE.ORIGINAL, startTime=0, endTime=n_samples - 1, interpolationMethod='none',
TimeValue=get_time_value_objs()
)],
ExponentialSmoothing=ExponentialSmoothing(
@@ -344,42 +254,30 @@ Source code for ExponentialSmoothing
-
+ Built with Sphinx using a
+ theme
+ provided by Read the Docs.
+
+
-
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/docs/_modules/index.html b/docs/_modules/index.html
index 7edd840e..6dc2c402 100644
--- a/docs/_modules/index.html
+++ b/docs/_modules/index.html
@@ -1,220 +1,110 @@
-
-
-
-
+
-
-
-
-
-
Overview: Module code — Nyoka 4.2.0 documentation
-
-
-
-
-
+
+
+
Overview: module code — Nyoka 5.5.0 documentation
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-