Skip to content
Snippets Groups Projects
Commit dd9457e0 authored by Arnaud Jaen's avatar Arnaud Jaen
Browse files

ENH: Expose K parameter to control number of neighbors used in KNN machine...

ENH: Expose K parameter to control number of neighbors used in KNN machine learning. Also expose IsRegression parameter.
parent 59a4cc52
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,20 @@ public:
itkNewMacro(Self);
itkTypeMacro(KNearestNeighborsMachineLearningModel, itk::MachineLearningModel);
/** Setters/Getters to the number of neighbors to use
* Default is 32
* see @http://docs.opencv.org/modules/ml/doc/k_nearest_neighbors.html
*/
itkGetMacro(K, int);
itkSetMacro(K, int);
/** Setters/Getters to IsRegression flag
* Default is False
* see @http://docs.opencv.org/modules/ml/doc/k_nearest_neighbors.html
*/
itkGetMacro(IsRegression, bool);
itkSetMacro(IsRegression, bool);
/** Train the machine learning model */
virtual void Train();
......@@ -89,6 +103,7 @@ private:
CvKNearest * m_KNearestModel;
int m_K;
int m_IsRegression;
};
} // end namespace otb
......
......@@ -26,10 +26,10 @@ namespace otb
template <class TInputValue, class TOutputValue>
KNearestNeighborsMachineLearningModel<TInputValue,TOutputValue>
::KNearestNeighborsMachineLearningModel()
::KNearestNeighborsMachineLearningModel() :
m_K(10), m_IsRegression(false)
{
m_KNearestModel = new CvKNearest;
m_K = 10;
}
......@@ -54,7 +54,7 @@ KNearestNeighborsMachineLearningModel<TInputValue,TOutputValue>
otb::ListSampleToMat<TargetListSampleType>(this->GetTargetListSample(),labels);
//train the KNN model
m_KNearestModel->train(samples,labels,cv::Mat(),false, m_K,false);
m_KNearestModel->train(samples,labels,cv::Mat(),m_IsRegression, m_K,false);
}
template <class TInputValue, class TOutputValue>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment