From 2cb47b4191ce2353f8d2b147f2ad597e98c8c8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorena=20Garc=C3=ADa?= Date: Tue, 4 Aug 2015 15:58:24 +0200 Subject: [PATCH 1/4] Update data.cpp Update to allow loading data from a .csv file that only contains training samples values and not the associated responses. To allow this behavior, function must be called with parameters ResponsesStartIdx <= -2 and ResponsesEndIdx = 0 --- modules/ml/src/data.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/ml/src/data.cpp b/modules/ml/src/data.cpp index d2ac18ff0..f224dbe64 100644 --- a/modules/ml/src/data.cpp +++ b/modules/ml/src/data.cpp @@ -636,9 +636,18 @@ public: vtypes[ninputvars] = VAR_CATEGORICAL; } - Mat(nsamples, noutputvars, CV_32F, &allresponses[0]).copyTo(tempResponses); - setData(tempSamples, ROW_SAMPLE, tempResponses, noArray(), noArray(), - noArray(), Mat(vtypes).clone(), tempMissing); + //If there are responses in the csv file, save them. If not, responses matrix will contain just zeros + if (noutputvars != 0){ + Mat(nsamples, noutputvars, CV_32F, &allresponses[0]).copyTo(tempResponses); + setData(tempSamples, ROW_SAMPLE, tempResponses, noArray(), noArray(), + noArray(), Mat(vtypes).clone(), tempMissing); + } + else{ + Mat zero_mat(nsamples, 1, CV_32F, Scalar(0)); + zero_mat.copyTo(tempResponses); + setData(tempSamples, ROW_SAMPLE, tempResponses, noArray(), noArray(), + noArray(), noArray(), tempMissing); + } bool ok = !samples.empty(); if(ok) std::swap(tempNameMap, nameMap); From fe6224380522385370c761a7f2257b388d43ed69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorena=20Garc=C3=ADa?= Date: Tue, 4 Aug 2015 16:37:41 +0200 Subject: [PATCH 2/4] Whitespace error --- modules/ml/src/data.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ml/src/data.cpp b/modules/ml/src/data.cpp index f224dbe64..b78b0d055 100644 --- a/modules/ml/src/data.cpp +++ b/modules/ml/src/data.cpp @@ -638,9 +638,9 @@ public: //If there are responses in the csv file, save them. If not, responses matrix will contain just zeros if (noutputvars != 0){ - Mat(nsamples, noutputvars, CV_32F, &allresponses[0]).copyTo(tempResponses); - setData(tempSamples, ROW_SAMPLE, tempResponses, noArray(), noArray(), - noArray(), Mat(vtypes).clone(), tempMissing); + Mat(nsamples, noutputvars, CV_32F, &allresponses[0]).copyTo(tempResponses); + setData(tempSamples, ROW_SAMPLE, tempResponses, noArray(), noArray(), + noArray(), Mat(vtypes).clone(), tempMissing); } else{ Mat zero_mat(nsamples, 1, CV_32F, Scalar(0)); From 4cd78bc7ad244c3c1ff94df648556a110886d8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorena=20Garc=C3=ADa?= Date: Tue, 4 Aug 2015 16:45:39 +0200 Subject: [PATCH 3/4] Whitespace error --- modules/ml/src/data.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ml/src/data.cpp b/modules/ml/src/data.cpp index b78b0d055..61aae4694 100644 --- a/modules/ml/src/data.cpp +++ b/modules/ml/src/data.cpp @@ -637,7 +637,7 @@ public: } //If there are responses in the csv file, save them. If not, responses matrix will contain just zeros - if (noutputvars != 0){ + if (noutputvars != 0){ Mat(nsamples, noutputvars, CV_32F, &allresponses[0]).copyTo(tempResponses); setData(tempSamples, ROW_SAMPLE, tempResponses, noArray(), noArray(), noArray(), Mat(vtypes).clone(), tempMissing); From c545857ea679aa633168883183976115a6514696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorena=20Garc=C3=ADa?= Date: Tue, 4 Aug 2015 16:50:55 +0200 Subject: [PATCH 4/4] Indent fix --- modules/ml/src/data.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ml/src/data.cpp b/modules/ml/src/data.cpp index 61aae4694..feb79d93a 100644 --- a/modules/ml/src/data.cpp +++ b/modules/ml/src/data.cpp @@ -638,9 +638,9 @@ public: //If there are responses in the csv file, save them. If not, responses matrix will contain just zeros if (noutputvars != 0){ - Mat(nsamples, noutputvars, CV_32F, &allresponses[0]).copyTo(tempResponses); - setData(tempSamples, ROW_SAMPLE, tempResponses, noArray(), noArray(), - noArray(), Mat(vtypes).clone(), tempMissing); + Mat(nsamples, noutputvars, CV_32F, &allresponses[0]).copyTo(tempResponses); + setData(tempSamples, ROW_SAMPLE, tempResponses, noArray(), noArray(), + noArray(), Mat(vtypes).clone(), tempMissing); } else{ Mat zero_mat(nsamples, 1, CV_32F, Scalar(0));