Deploy pandas transformation as a machine learning model

Viewed 13

I would like to deploy a simple pandas dataframe transformation as a machine learning model.

Say, I have:

X = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})

How to create a 'model', which after the call pred = model.predict(X)

will "predict" a sum of A and B: pred = df['A'] + df['B'] ?

My use case is to treat it as a kind of baseline model in my ML experiments, in which I will encode different heuristics.

Having such a "model" I would like to be able to eg pickle it and deploy on some endpoint to serve "human predictions".

Many thanks in advance :)

Andy

1 Answers

Isn't this standard in OOP:

class Model:
    def predict(self, df):
        # might need to check that A, B are in the columns
        return df['A'] + df['B']

model = Model()
model.predict(X)
Related