Skip to content
Snippets Groups Projects
Commit 37091ac9 authored by Julien Michel's avatar Julien Michel
Browse files

ENH: Giving access to variables importance matrix in...

ENH: Giving access to variables importance matrix in RandomForestsMachineLearningModel (patch kindly contributed by Adrien Gressin)
parent 27f02b66
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@
#include "itkFixedArray.h"
#include "itkListSample.h"
#include "otbMachineLearningModel.h"
#include "itkVariableSizeMatrix.h"
class CvRTrees;
......@@ -48,6 +49,10 @@ public:
typedef TTargetValue TargetValueType;
typedef itk::FixedArray<TargetValueType,1> TargetSampleType;
typedef itk::Statistics::ListSample<TargetSampleType> TargetListSampleType;
// Other
typedef itk::VariableSizeMatrix<float> VariableImportanceMatrixType;
//opencv typedef
typedef CvRTrees RFType;
......@@ -159,11 +164,9 @@ public:
itkGetMacro(TerminationCriteria, int);
itkSetMacro(TerminationCriteria, int);
// cv::Mat GetVariableImportance()
// {
// return m_RFModel->getVarImportance();
// }
/** Returns a matrix containing variable importance */
VariableImportanceMatrixType GetVariableImportance();
float GetTrainError();
protected:
......
......@@ -183,6 +183,24 @@ RandomForestsMachineLearningModel<TInputValue,TOutputValue>
return false;
}
template <class TInputValue, class TOutputValue>
typename RandomForestsMachineLearningModel<TInputValue,TOutputValue>
::VariableImportanceMatrixType
RandomForestsMachineLearningModel<TInputValue,TOutputValue>
::GetVariableImportance()
{
cv::Mat cvMat = m_RFModel->getVarImportance();
VariableImportanceMatrixType itkMat(cvMat.rows,cvMat.cols);
for(unsigned int i =0; i<cvMat.rows; i++)
{
for(unsigned int j =0; j<cvMat.cols; j++)
{
itkMat(i,j)=cvMat.at<float>(i,j);
}
}
return itkMat;
}
template <class TInputValue, class TOutputValue>
void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment