python – Get features of a ML model called from a flask API endpoint


def get_features(input_id):
    length = get_length(input_id)
    width = get_width(input_id)
    height = get_height(input_id)

    features = {
        'input_id': input_id,
        'features': (
            {
                'feature_name': 'length',
                'description': '',
                'data_source': 'DS1',
                'isPresent': True if length else False,
                'value': length or None
            },
            {
                'feature_name': 'width',
                'description': '',
                'data_source': 'DS2',
                'isPresent': True if width else False,
                'value': width or None
            },
            {
                'feature_name': 'height',
                'description': '',
                'data_source': 'DS1',
                'isPresent': True if height else False,
                'value': height or None
            },
        )
    }

    return features

In terms of the data structure, the data source is going to be specific and I can have a map of them, but I don’t see much value in it. Would a better practice be to store these as a relational table? We are using features of model during a prediction as a JSON value in Postgres.