I'm building a simple polynomial model in Python using sklearn. My training set consists of 3-feature vectors (i.e. RGB triplets). I'm fitting a model using the following code:
degree = 1
model = make_pipeline(PolynomialFeatures(degree), Ridge())
model.fit(samples, y)
coef = model.named_steps['ridge'].coef_
intercept = model.named_steps['ridge'].intercept
All good using a one degree polynomial. This is the output:
Coefficients = [[ 0., -0.1235785, 0.8367021, -1.71648988]]
Intercept = [ 9.15605047]
In order to evaluate a new triplet with the model I just trained I could make use of:
prediction = model.predict(aNewTriplet)
Alternatively, I could do:
prediction = intercept + (-0.123578 * aNewTriplet[0] + 0.8367021 * aNewTriplet[1] - 1.71648988 * aNewTriplet[2])
What about if I have a second order polynomial (which outputs an array of 10 elements)? How would the coefficients be ordered? Like this?:
coefficients (order = 2) = [ 0, R, G, B, R^2, G^2, B^2, RG, RB, GR]