Medial Code Documentation
Loading...
Searching...
No Matches
MedKNN.h
1#pragma once
3
4
5//======================================================================================
6// KNN
7//======================================================================================
8typedef enum {
9 KNN_DIST_MEAN,
10 KNN_1_DIST,
11 KNN_WEIGHTEDLS,
12 KNN_AVG_LAST
13} knnAveraging;
14
15typedef enum {
16 KNN_L1,
17 KNN_L2,
18 KNN_METRIC_LAST
19}knnMetric;
20
22
23 int k;
24 knnAveraging knnAv;
25 knnMetric knnMetr;
26
27 ADD_CLASS_NAME(MedKNNParams)
28 ADD_SERIALIZATION_FUNCS(k, knnAv, knnMetr)
29};
30
31class MedKNN : public MedPredictor {
32public:
33 // Model
34 int nsamples;
35 int nftrs;
36 vector<float> x;
37 vector<float> y;
38 vector<float> w;
39
40
41 // Parameters
42 MedKNNParams params;
43
44
45 // Function
46 MedKNN();
47 MedKNN(void *params);
48 MedKNN(MedKNNParams& params);
51 virtual int set_params(map<string, string>& mapper);
52 int init(void *params);
53 knnAveraging get_knn_averaging(string name);
54 knnMetric get_knn_metric(string name);
55
56 int Learn(float *x, float *y, const float *w, int nsamples, int nftrs);
57 int Predict(float *x, float *&preds, int nsamples, int nftrs) const;
58
59 ADD_CLASS_NAME(MedKNN)
60 ADD_SERIALIZATION_FUNCS(classifier_type, params, nsamples, nftrs, x, y, w)
61};
62
MedAlgo - APIs to different algorithms: Linear Models, RF, GBM, KNN, and more.
#define ADD_SERIALIZATION_FUNCS(...)
Definition SerializableObject.h:122
#define MEDSERIALIZE_SUPPORT(Type)
Definition SerializableObject.h:108
Definition MedKNN.h:31
int Predict(float *x, float *&preds, int nsamples, int nftrs) const
Predict should be implemented for each model.
Definition MedKNN.cpp:124
virtual int set_params(map< string, string > &mapper)
The parsed fields from init command.
Definition MedKNN.cpp:60
int Learn(float *x, float *y, const float *w, int nsamples, int nftrs)
Learn should be implemented for each model.
Definition MedKNN.cpp:99
Base Interface for predictor.
Definition MedAlgo.h:78
MedPredictorTypes classifier_type
The Predicotr enum type.
Definition MedAlgo.h:80
Definition SerializableObject.h:32
Definition MedKNN.h:21