| 8 | #include <utility> |
| 9 | |
| 10 | class TLinearModel { |
| 11 | private: |
| 12 | TVector<double> Coefficients; |
| 13 | double Intercept; |
| 14 | |
| 15 | public: |
| 16 | Y_SAVELOAD_DEFINE(Coefficients, Intercept); |
| 17 | |
| 18 | TLinearModel(TVector<double>&& coefficients, const double intercept) |
| 19 | : Coefficients(std::move(coefficients)) |
| 20 | , Intercept(intercept) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | explicit TLinearModel(size_t featuresCount = 0) |
| 25 | : Coefficients(featuresCount) |
| 26 | , Intercept(0.) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | const TVector<double>& GetCoefficients() const { |
| 31 | return Coefficients; |
| 32 | } |
| 33 | |
| 34 | double GetIntercept() const { |
| 35 | return Intercept; |
| 36 | } |
| 37 | |
| 38 | template <typename T> |
| 39 | double Prediction(const TVector<T>& features) const { |
| 40 | return InnerProduct(Coefficients, features, Intercept); |
| 41 | } |
| 42 | }; |