Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
linenumberstrue
import json
import requests

# Setup environment
environment = {}
with open("params.json") as params_file:
    environment = json.loads(params_file.read())

algo_config_name = "my_ml_configuration"
algo_config = {}
# Download regions and properties
response = requests.get(
    'http://localhost:8002/region/%s/list?cadence=%s&time_start=between(%s,%s)'
    % (
        environment['algorithm']['dataset'],
        environment['algorithm']['cadence'],
        environment['algorithm']['time_start'],
        environment['algorithm']['time_end']
    )
).json()
if response['has_error'] == True:
    raise ValueError('No data found!')
else:
    # if we already have an algorithm configuration stored within the database,
    # we do not need to extract any train not validation data
    (train_data, validation_data, test_data) = createDataPartitions(response['data'])

# Setup model
model = MyMLAlgorithm(envirnoment['algorithm']['params'])

# Check wherever we have to train our algorithm or if we can download an already existing configuration
response = requests.get(
    'http://localhost:8004/algoconfig/list?algorithm_config_name=%s&algorithm_config_version=latest%s'
    % algo_config_name)(environment['algorithm']['cfg_name'], 'latest')
).json()
if response['has_error'] == False and response['result-count'] > 0:
	    # as we requested the latest configuration we expect only one result within 'data'
    algo_configcfg = response['data'][0]
    model.set_parameters(algo_cfg)
else:
    #
http://localhost:8004/algoconfig/list?algorithm_config_name=a #iftrain_model(
        model, train_data, validation_data,
        envirnoment['algorithm']['max_epoches'], envirnoment['algorithm']['batch_size'],
        environment
    )


Now the problem is that the ml_result is not structured in the way that the prediction service would understand it. So we have to restructure it to accomplish following definition:

...