poly method

List<double> poly(
  1. List<double> X
)

Polynomial kernel.

K(X, Y) = (gamma <X, Y> + coef0)^degree

Implementation

List<double> poly(List<double> X) {
  List<double> kernels = List.generate(
    supportVectors.length,
    ((index) => index.toDouble()),
  );
  for (int i = 0; i < supportVectors.length; i++) {
    double kernel = 0.0;
    for (int j = 0; j < supportVectors[i].length; j++) {
      kernel += supportVectors[i][j] * X[j];
    }
    kernels[i] =
        pow((this.gamma * kernel) + this.coef0, this.degree).toDouble();
  }
  return kernels;
}