# Changeset 1189

Ignore:
Timestamp:
Feb 29, 2008, 12:58:04 PM (10 years ago)
Message:

NCC fixed for #75

Location:
trunk/yat/classifier
Files:
2 edited

Unmodified
Removed
• ## trunk/yat/classifier/KNN.h

 r1188 /** @brief Nearest Neighbor Classifier \brief Nearest Neighbor Classifier A sample is predicted based on the classes of its k nearest public: /** @brief Default constructor. \brief Default constructor. The number of nearest neighbors (k) is set to 3. Distance and /** @brief Constructor using an intialized distance measure. The number of nearest neighbors (k) is set to 3. This constructor should be used if Distance has parameters and the user wants to specify the parameters by initializing Distance prior to constructing the KNN. \brief Constructor using an intialized distance measure. The number of nearest neighbors (k) is set to 3. NeighborWeighting is initialized using its default constructor. This constructor should be used if Distance has parameters and the user wants to specify the parameters by initializing Distance prior to constructing the KNN. */ KNN(const Distance&); /** @brief Make predictions for unweighted test data. \brief Make predictions for unweighted test data. Predictions are calculated and returned in \a results.  For /** @brief Make predictions for weighted test data. \brief Make predictions for weighted test data. Predictions are calculated and returned in \a results. For /** @brief Train the KNN using unweighted training data with known \brief Train the KNN using unweighted training data with known targets.
• ## trunk/yat/classifier/NCC.h

 r1174 /// /// @brief Class for Nearest Centroid Classification. /// /// The template argument Distance should be a class modelling /// the concept \ref concept_distance. /// /** \brief Nearest Centroid Classifier A sample is predicted based on its distance to centroids for each class. The centroids are generated using training data. NCC supports using different measures, for example, Euclidean distance, to define distance between samples and centroids. The template argument Distance should be a class modelling the concept \ref concept_distance. */ template class NCC : public SupervisedClassifier public: /// /// @brief Constructor /// /** \brief Constructor Distance is initialized using its default constructor. */ NCC(void); /// /// @brief Constructor /// /** \brief Constructor using an initialized distance measure This constructor should be used if Distance has parameters and the user wants to specify the parameters by initializing Distance prior to constructing the NCC. */ NCC(const Distance&); /// /// @brief Destructor /// /** Destructor */ virtual ~NCC(void); /// /// @return the centroids for each class as columns in a matrix. /// /** \brief Get the centroids for all classes. \return The centroids for each class as columns in a matrix. */ const utility::Matrix& centroids(void) const; NCC* make_classifier(void) const; /// /// Train the classifier with a training data set and /// targets. Centroids are calculated for each class. /// void train(const MatrixLookup&, const Target&); /// /// Train the classifier with a weighted training data set and /// targets. Centroids are calculated for each class. /// void train(const MatrixLookupWeighted&, const Target&); /// /// Calculate the distance to each centroid for test samples /// void predict(const MatrixLookup&, utility::Matrix&) const; /// /// Calculate the distance to each centroid for weighted test samples /// void predict(const MatrixLookupWeighted&, utility::Matrix&) const; /** \brief Make predictions for unweighted test data. Predictions are calculated and returned in \a results.  For each sample in \a data, \a results contains the distances to the centroids for each class. If a class has no training samples NaN's are returned for this class in \a results. Weighted distance calculations, in which NaN's have zero weights, are used if the centroids contain NaN's. \note NCC returns distances to centroids as the prediction. This means that the best class for a sample has the smallest value in \a results. This is in contrast to, for example, KNN for which the best class for a sample in \a results has the largest number (the largest number of nearest neighbors). */ void predict(const MatrixLookup& data, utility::Matrix& results) const; /** \brief Make predictions for weighted test data. Predictions are calculated and returned in \a results.  For each sample in \a data, \a results contains the distances to the centroids for each class as in predict(const MatrixLookup& data, utility::Matrix& results). Weighted distance calculations are used, and zero weights are used for NaN's in centroids.  If for a test sample and centroid pair, all variables have either zero weight for the test sample or NaN for the centroid, the centroid and the sample have no variables with values in common. In this case the prediction for the sample is set to NaN for the class in \a results. \note NCC returns distances to centroids as the prediction. This means that the best class for a sample has the smallest value in \a results. This is in contrast to, for example, KNN for which the best class for a sample in \a results has the largest number (the largest number of nearest neighbors). */ void predict(const MatrixLookupWeighted& data, utility::Matrix& results) const; /** \brief Train the NCC using unweighted training data with known targets. A centroid is calculated for each class. For each variable in \a data, a centroid for a class contains the average value of the variable across all training samples in the class. */ void train(const MatrixLookup& data, const Target& targets); /** \brief Train the NCC using weighted training data with known targets. A centroid is calculated for each class as in train(const MatrixLookup&, const Target&). The weights of the data are used when calculating the centroids and the centroids should be interpreted as unweighted (i.e. centroid values have unity weights). If a variable has zero weights for all samples in a class, the centroid is set to NaN for that variable. */ void train(const MatrixLookupWeighted& data, const Target& targets); bool centroids_nan_; Distance distance_; }; /// /// The output operator for the NCC class. /// //  std::ostream& operator<< (std::ostream&, const NCC&); }; // templates
Note: See TracChangeset for help on using the changeset viewer.