The following code represents an attempt at a minimal, reproducible example which compiles and runs as expected.
import numpy as np
from sklearn import model_selection as skms
N = 20
ftr = np.linspace(-10,10,num=N) # ftr values
tgt = 2*ftr**2 -3 + np.random.uniform(-2,2,N) # tgt =func(ftr)
(train_ftr, test_ftr, train_tgt, test_tgt) = skms.train_test_split(ftr, tgt,
test_size = N//2)
model_one = np.poly1d(np.polyfit(train_ftr, train_tgt, 1))
preds_one = model_one(test_ftr)
Where the following are of type numpy ndarrays.
train_ftr
test_ftr
train_tgt
test_tgt
My question relates to the output of the last line preds_one wrt the second last line model_one. In the last line, how can you pass a parameter test_ftr to the function model_one defined in the second last line when model_one is a composite function? That is, what is test_ftr actually being passed to?
model_oneis not a composite function, it is a class instance of thenumpy.poly1dclass. A class instance can be callable, depending on whether you have its__call__method defined (in this case: yes). So calling a class instance such aspreds_one = model_one(test_ftr)is a simplified expression ofpreds_one = model_one.__call__(test_ftr).