func (m *LinearModel) FitTransform(x, y num.Matrix) num.Matrix { xT := x.Transpose() m.Coefs = (xT.Times(x)).Inverse().Times(xT).Times(y) predicted := x.Times(m.Coefs) m.Error = 0.0 for j := 0; j < predicted.Shape[0]; j++ { m.Error += math.Pow(predicted.Data[j][0]-y.Data[j][0], 2) } m.Error /= float64(predicted.Shape[0]) return predicted }
func (m LinearModel) Transform(x num.Matrix) num.Matrix { return x.Times(m.Coefs) }