PolyFitMultivariate class
Polynomial regression with several input features and several outputs.
Fits every output as a polynomial of degree degree of the features,
including the interaction terms (x0 * x1, x0^2 * x2...), by least
squares. It is equivalent to sklearn.preprocessing.PolynomialFeatures
followed by a linear regression without intercept, and the terms follow
the same order (see powers).
When there are not enough samples for the number of terms, the minimum
norm least squares solution is used, like numpy.linalg.lstsq.
References
- "Polynomial regression". https://en.wikipedia.org/wiki/Polynomial_regression. Retrieved 2026-10-13.
- "sklearn.preprocessing.PolynomialFeatures". https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html. Retrieved 2026-10-13.
- "numpy.linalg.lstsq". https://numpy.org/doc/stable/reference/generated/numpy.linalg.lstsq.html. Retrieved 2026-10-13.
Examples
// z = 1 + 2a + 3b + ab, with two features (a, b) and one output
var x = Array2d([
Array([0, 0]), Array([1, 0]), Array([0, 1]),
Array([1, 1]), Array([2, 1]), Array([1, 2]),
]);
var y = Array2d(x.map((r) => Array([1 + 2 * r[0] + 3 * r[1] + r[0] * r[1]])).toList());
var p = PolyFitMultivariate(x, y, 2);
print(p.predict(Array([2, 2])));
/* output:
Array([15.000000000000004])
*/
Constructors
- PolyFitMultivariate(Array2d x, Array2d y, int degree)
- Fits the polynomial.
Properties
- coefficients ↔ Array2d
-
Coefficients:
coefficients[t][o]multiplies termtfor outputo.latefinal - degree → int
-
Degree of the polynomial.
final
- featureCount → int
-
Number of input features.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- outputCount → int
-
Number of outputs.
final
-
powers
→ List<
List< int> > -
Exponent of each feature in each term:
powers[t][f]is the exponent of featurefin termt. Same order asPolynomialFeatures.powers_.final - rank ↔ int
-
Rank of the matrix of terms. Smaller than powers.length when there
are not enough distinct samples for all the terms.
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
predict(
Array features) → Array - Predicted outputs for one sample with featureCount features.
-
predictAll(
Array2d samples) → Array2d -
Predicted outputs for each row of
samples. -
R2(
) → Array - Coefficient of determination R² of each output (1.0 for a constant output).
-
sse(
) → Array - Sum of squared residuals of each output.
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited