MATLAB: How to extract a polynomial equation from regressionLearner


I am wondering how I can extract a resulting fitting equation from Matlab's regressionLearner (version R2017b)? I am using the linear regression with quadratic terms to fit the variable "C" as a function the variables "H2O", "CO2" and "P". I have exported the compact model into my workspace:
When I open the structure and click on "LinearModel", I find the supposedly used equation form under "Formula" as
LinearPredictor '1 + H2O*CO2 + H2O*P + CO2*P + H2O^2 + CO2^2 + P^2'
This formula has 7 terms. However, under "TermNames" 10 terms are listed, and under coefficients I find estimates for each of these terms, including standard error SE, tStat and pValue.
How do these ten terms relate to the seven terms in the LinearPredictor equation above? The LinearPredictor equation is missing terms with only H2O, CO2, and P, and instead of H2O:P it contains H2O*P etc. Are these supposed to be the same? Is this even the best way to extract a polynomial equation from the regressionLearner?

Best Answer

  • Okay, a few tests later I figured it out - for anyone else wondering about a similar problem, forget about the equation in linearPredictor!
    In this case, your equation would look like this:
    A(H2O,CO2,P) = coeff(1) + coeff(2)*H2O + coeff(3)*CO2 + coeff(4)*P + coeff(5)*H2O*CO2 + coeff(6)*H2O*P + coeff(7)*CO2*P + coeff(8)*H2O^2 + coeff(9)*CO2^2 + coeff(10)*P^2
    with coeff being the different values for each term from column 1 ("estimate") in the coefficients category.