Implements experimental regressor that produces weighted average of the predicted variable over neighbours, weighted by distance.
More...
|
|
typedef Regressor< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > | parent |
| | the immediate abstract base
|
|
typedef Clonable_Impl< Regressor_Weighted_Neighbours, parent > | parent_impl |
| | implements clone(); sharing/stateless_clone throw in Regressor
|
|
typedef std::shared_ptr< DATAACCESSOR > | PDataAccessor |
| | shared pointer to the data accessor supplying train/test blocks
|
|
typedef std::shared_ptr< SUBSET > | PSubset |
| | shared pointer to the feature subset being trained/evaluated on
|
|
typedef DATAACCESSOR::PPattern | PPattern |
| | one data sample as exposed by DATAACCESSOR (a raw pointer to its feature vector)
|
|
typedef std::shared_ptr< DATAACCESSOR > | PDataAccessor |
| | shared pointer to the data accessor supplying train/test blocks
|
|
typedef std::shared_ptr< SUBSET > const | PSubset |
| | shared pointer to the (fixed, non-reassignable) feature subset being evaluated
|
|
typedef DATAACCESSOR::PPattern | PPattern |
| | one data sample as exposed by DATAACCESSOR (a raw pointer to its feature vector)
|
|
|
void | set_kernel_multiplier (const RETURNTYPE m) |
| | scales the Gaussian kernel width used by get_weight(); width = distance stddev * m (must be > 0)
|
|
RETURNTYPE | get_kernel_size () const |
| | the effective kernel width (training-set pairwise-distance stddev times the multiplier set by set_kernel_multiplier())
|
|
void | set_dependent_index (const IDXTYPE depvaridx) |
| | data column to predict; the (IDXTYPE)-1 default/sentinel selects the class label instead ("regression simulating classification")
|
| virtual bool | predict (RETURNTYPE &depvar, const PPattern &pattern) override |
| | Predicts the dependent variable of one pattern into depvar (see the dependent-variable convention in the class documentation). Returns false when no prediction can be made at all - the regressor has not been trained, or the implementation hit an unrecoverable condition; false aborts the enclosing test loop.
|
| virtual bool | train (const PDataAccessor da, const PSubset sub) override |
| virtual bool | test (RETURNTYPE &result, const PDataAccessor da) override |
| virtual bool | test_metric (RETURNTYPE &result, const PDataAccessor da, const Metric_Spec< RETURNTYPE > &spec) override |
| virtual std::ostream & | print (std::ostream &os) const override |
| | writes a human-readable identification of the object; base default writes nothing
|
| Regressor< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > * | clone () const override |
| | dispatches to the DEEP_KIND mechanism (default CLONE_DEEP: Derived's copy-constructor)
|
| Regressor< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > * | sharing_clone () const override |
| | dispatches to the SHARING_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
|
| Regressor< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR > * | stateless_clone () const override |
| | dispatches to the STATELESS_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
|
| virtual bool | train (const PDataAccessor da, const PSubset sub)=0 |
| Regressor * | sharing_clone () const override |
| Regressor * | stateless_clone () const override |
| bool | is_clone () const |
|
bool | is_sharing () const |
| | true if this instance is a sharing_clone() result (referencing, not owning, the source's structures)
|
|
bool | is_sharing_clone () const |
| | true if this instance is BOTH a clone and sharing – i.e. specifically a sharing_clone() result, not a clone()/stateless_clone() one
|
template<class RETURNTYPE, typename DATATYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR, class DISTANCE>
class FST::Regressor_Weighted_Neighbours< RETURNTYPE, DATATYPE, IDXTYPE, DIMTYPE, SUBSET, DATAACCESSOR, DISTANCE >
Implements experimental regressor that produces weighted average of the predicted variable over neighbours, weighted by distance.
A prediction is the Gaussian-kernel weighted average of the dependent variable over ALL training patterns (not the k nearest ones): weight(dist) falls off with the distance in the selected subspace, the kernel width being the standard deviation of the training set's pairwise distances times the multiplier set by set_kernel_multiplier().
EXPERIMENTAL means: the method is offered for exploration, not as a tuned or validated regressor. Specifically – the kernel width is derived from the data rather than cross-validated; every training pattern contributes to every prediction, so there is no locality parameter to tune; and no distance normalization across features is applied beyond whatever the DISTANCE template argument and the data scaler do.
- Note
- The DEPENDENT VARIABLE is by default the CLASS LABEL, not a data column: with the default (IDXTYPE)-1 sentinel the class index of each training pattern is the value being averaged ("regression simulating classification"), and test() then counts a prediction within 0.5 of the true label as correct, so its result reads like an accuracy. set_dependent_index() switches to a genuine data column, in which case train() excludes that column from the distance computation and test() returns the negated mean absolute error (FST4 always maximizes).
- Warning
- COST: train() computes ALL pairs of training-set distances, i.e. O(N^2) distance evaluations in the subset dimensionality, and keeps one value per pair in memory. predict() costs O(N) per pattern, so one test() pass over M test patterns costs O(M*N). This regressor is meant for small datasets.
- Note
- Degenerate data (all training patterns identical, or a kernel width of zero) leads to divisions by zero that are only caught by assertions – see train() and predict().
template<class RETURNTYPE, typename DATATYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR, class DISTANCE>
Predicts the dependent variable of one pattern into depvar (see the dependent-variable convention in the class documentation). Returns false when no prediction can be made at all - the regressor has not been trained, or the implementation hit an unrecoverable condition; false aborts the enclosing test loop.
Implements FST::Regressor< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR >.
template<class RETURNTYPE, typename DATATYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR, class DISTANCE>
Over the designated test part: the fraction of predictions within 0.5 of the true class label (an accuracy) in the default class-label mode, or the negated mean absolute error when a data column is the dependent variable. Returns false if the test part is empty.
Implements FST::Regressor< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR >.
template<class RETURNTYPE, typename DATATYPE, typename IDXTYPE, typename DIMTYPE, class SUBSET, class DATAACCESSOR, class DISTANCE>
evaluates the designated test data under the given regression metric (r2/neg-rmse/neg-mae); the default spec is served by test() itself. Classification metrics do not apply to a regression stack and make this return false. The dependent-variable convention is the concrete regressor's - see the class documentation.
Reimplemented from FST::Regressor< RETURNTYPE, DIMTYPE, SUBSET, DATAACCESSOR >.