Skip to content

How can I predict the outputs using a prediction function? [closed]

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



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)

   C  Z   R
0  1  4  20
1  2  5  36
2  3  6  66
User contributions licensed under: CC BY-SA
8 People found this is helpful