4 #include "PrimalRegressor.hpp"
5 #include "ufjfmltk/core/DistanceMetric.hpp"
13 template<
typename T =
double,
typename Callable = metrics::dist::Eucl
idean <T> >
19 Callable dist_function;
35 auto points = this->
samples->points();
36 std::vector<double> distances(this->
samples->size());
37 std::vector<int> classes = this->
samples->classes();
38 std::vector<size_t> idx(distances.size()), freq(classes.size());
39 auto p0 = std::make_shared<Point<T> >(p);
41 std::iota(idx.begin(), idx.end(), 0);
44 std::transform(points.begin(), points.end(), distances.begin(),
45 [p0,
this](
const std::shared_ptr<
Point<T> > q) {
46 return this->dist_function(*p0, *q);
49 std::stable_sort(idx.begin(), idx.end(), [&distances](
size_t i1,
size_t i2) {
50 return distances[i1] < distances[i2];
56 for (
size_t j = 0; j < this->k; j++) {
57 sum += points[idx[j]]->Y();
std::shared_ptr< Data< T > > samples
Samples used in the model training.
Definition: Learner.hpp:21
Wrapper for the implementation of the K-Nearest Neighbors regression algorithm.
Definition: KNNRegressor.hpp:14
double evaluate(const Point< T > &p, bool raw_value=false) override
Returns the class of a feature point based on the trained Learner.
Definition: KNNRegressor.hpp:34
std::string getFormulationString() override
getFormulationString Returns a string that represents the formulation of the learner (Primal or Dual)...
Definition: KNNRegressor.hpp:30
bool train() override
Function that execute the training phase of a Learner.
Definition: KNNRegressor.hpp:26
Definition: PrimalRegressor.hpp:11
UFJF-MLTK main namespace for core functionalities.
Definition: classifier/Classifier.hpp:11