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?
JavaScript
x
3
1
def objective(C, Z)
2
return C**3 + Z**2 + 3
3
Advertisement
Answer
here is what you want in pandas.
JavaScript
1
12
12
1
import pandas as pd
2
3
def objective(C, Z):
4
return C**3 + Z**2 + 3
5
6
data = {'C': [1,2,3], 'Z': [4,5,6]}
7
df = pd.DataFrame(data)
8
9
df['R'] = df.apply(lambda x: objective(x.C, x.Z), axis=1)
10
11
print(df)
12
JavaScript
1
5
1
C Z R
2
0 1 4 20
3
1 2 5 36
4
2 3 6 66
5