In a production environment, the model will be trained and stored on object storage using a different approach. This sample is considering a model already trained and serialized. ''' #model file is loaded in memory rel_path = 'models/base_model_LSTM64_LSTM32_Dropout0.375240min_new' #relative path for the model script_dir = os.path.dirname(__file__) #absolute dir the script is in abs_file_path = os.path.join(script_dir, rel_path) model_file = open(abs_file_path, 'rb') #create bucket on COS to store the model bucket_name = credentials['tennant_id'] + '-analytics-' + 'models' db.cos_create_bucket(bucket=bucket_name) #store model on COS db.cos_save(persisted_object=model_file.read(), filename='base_model_LSTM64_LSTM32_Dropout0.375240min_new', bucket=bucket_name, binary=True) ''' We now have 12 hours of historical data. We can use it to do some calculations. The calculations will be placed into a container called a pipeline. The pipeline is constructed from multiple stages. Each stage performs a transforms the data. The execute() method retrieves entity data and carries out the transformations. By specifying 'to_csv = True', we also csv output dumped at the end of each stage. This is useful for testing. 'register=true' took care of function registration so the ForecastKerasModel function will be available in the ui. You can use the outputs of one calculation in another. This function is receiving a dummy value as input, and will generate four predictions as outputs. The output definitions are declared in the function class.
''' You can serialize simple functions to Cloud Object Storage to avoid having to paste replicas of them in the UI or avoid the need to manage them in a git repository See offline simple functions sample to see how to create simple functions. Here is a simple function: ''' def f(df, parameters=None): # generate an 2-D array of random numbers output = np.random.normal(1, 0.1, len(df.index)) return output ''' First save the function in cloud object storage ''' db.cos_save(persisted_object=f, filename='random_1', binary=True) ''' Test the function by adding it to an entity type ''' test_function = bif.PythonFunction(function_code='random_1', input_items=['speed'], output_item='random_1_out', parameters={}) test_function.execute_local_test(db=db, db_schema=db_schema)