I’ve created my own prediction function (`R=C^3+Z^2+3`

) to predict my target variable. The problem is now I am dealing with a *prediction function* not an algorithm; therefore `.predict`

from scikit-learn won’t work. But then how can I get my predictions?

def objective(C, Z) return C**3 + Z**2 + 3

## Advertisement

## Answer

here is what you want in pandas.

import pandas as pd def objective(C, Z): return C**3 + Z**2 + 3 data = {'C': [1,2,3], 'Z': [4,5,6]} df = pd.DataFrame(data) df['R'] = df.apply(lambda x: objective(x.C, x.Z), axis=1) print(df)

C Z R 0 1 4 20 1 2 5 36 2 3 6 66