How can I predict the outputs using a prediction function?

Question:

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
Asked By: user20155022

||

Answers:

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
Answered By: Amin S
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.