blob: 649ccd6988421c857173ffedfc2fc575bc5b1583 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  | 
#pragma once
#include <util/generic/algorithm.h>
#include <util/generic/vector.h>
#include <util/ysaveload.h>
#include <utility>
class TLinearModel { 
private:
    TVector<double> Coefficients;
    double Intercept;
public:
    Y_SAVELOAD_DEFINE(Coefficients, Intercept);
    TLinearModel(TVector<double>&& coefficients, const double intercept)
        : Coefficients(std::move(coefficients))
        , Intercept(intercept)
    {
    }
    explicit TLinearModel(size_t featuresCount = 0)
        : Coefficients(featuresCount)
        , Intercept(0.)
    {
    }
    const TVector<double>& GetCoefficients() const {
        return Coefficients;
    }
 
    double GetIntercept() const {
        return Intercept;
    }
 
    template <typename T>
    double Prediction(const TVector<T>& features) const {
        return InnerProduct(Coefficients, features, Intercept);
    }
};
  |