|
@@ -12,7 +12,7 @@ app = Flask('model_prediction_bp——service')
|
|
def model_prediction(df,args):
|
|
def model_prediction(df,args):
|
|
if 'is_limit' in df.columns:
|
|
if 'is_limit' in df.columns:
|
|
df = df[df['is_limit'] == False]
|
|
df = df[df['is_limit'] == False]
|
|
- features, time_steps, col_time, model_name,col_reserve = str_to_list(args['features']), int(args['time_steps']),args['col_time'],args['model_name'],str_to_list(args['col_reserve'])
|
|
|
|
|
|
+ features, time_steps, col_time, model_name,col_reserve,howlongago = str_to_list(args['features']), int(args['time_steps']),args['col_time'],args['model_name'],str_to_list(args['col_reserve']),int(args['howlongago'])
|
|
feature_scaler,target_scaler = get_scaler_model_from_mongo(args)
|
|
feature_scaler,target_scaler = get_scaler_model_from_mongo(args)
|
|
df = df.sort_values(by=col_time).fillna(method='ffill').fillna(method='bfill')
|
|
df = df.sort_values(by=col_time).fillna(method='ffill').fillna(method='bfill')
|
|
scaled_features = feature_scaler.transform(df[features])
|
|
scaled_features = feature_scaler.transform(df[features])
|
|
@@ -21,11 +21,12 @@ def model_prediction(df,args):
|
|
# model = load_model(f'{farmId}_model.h5', custom_objects={'rmse': rmse})
|
|
# model = load_model(f'{farmId}_model.h5', custom_objects={'rmse': rmse})
|
|
model = get_h5_model_from_mongo(args)
|
|
model = get_h5_model_from_mongo(args)
|
|
y_predict = list(chain.from_iterable(target_scaler.inverse_transform([model.predict(scaled_features).flatten()])))
|
|
y_predict = list(chain.from_iterable(target_scaler.inverse_transform([model.predict(scaled_features).flatten()])))
|
|
|
|
+ result['howlongago'] = howlongago
|
|
result = df[-len(y_predict):]
|
|
result = df[-len(y_predict):]
|
|
result['predict'] = y_predict
|
|
result['predict'] = y_predict
|
|
result.loc[result['predict'] < 0, 'predict'] = 0
|
|
result.loc[result['predict'] < 0, 'predict'] = 0
|
|
result['model'] = model_name
|
|
result['model'] = model_name
|
|
- features_reserve = col_reserve + ['model', 'predict']
|
|
|
|
|
|
+ features_reserve = col_reserve + ['model', 'predict', 'howlongago']
|
|
return result[set(features_reserve)]
|
|
return result[set(features_reserve)]
|
|
|
|
|
|
|
|
|