Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
3cdd2b27
Commit
3cdd2b27
authored
Nov 05, 2013
by
Rahul Kavi
Committed by
Maksim Shabunin
Aug 18, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated logistic regression program with new api example
parent
af88f0c0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
9 deletions
+18
-9
logistic_regression.cpp
samples/cpp/logistic_regression.cpp
+18
-9
No files found.
samples/cpp/logistic_regression.cpp
View file @
3cdd2b27
...
...
@@ -76,6 +76,7 @@ int main()
Mat
labels_train
,
labels_test
;
Mat
responses
,
result
;
FileStorage
fs1
,
fs2
;
FileStorage
f
;
...
...
@@ -120,12 +121,17 @@ int main()
cout
<<
"initializing Logisitc Regression Parameters
\n
"
<<
endl
;
LogisticRegressionParams
params
=
LogisticRegressionParams
(
0.001
,
10
,
LogisticRegression
::
REG_L2
,
1
,
LogisticRegression
::
BATCH
,
1
);
// LogisticRegressionParams params1 = LogisticRegressionParams(0.001, 10, LogisticRegression::BATCH, LogisticRegression::REG_L2, 1, 1);
// params1 (above) with batch gradient performs better than mini batch gradient below with same parameters
LogisticRegressionParams
params1
=
LogisticRegressionParams
(
0.001
,
10
,
LogisticRegression
::
MINI_BATCH
,
LogisticRegression
::
REG_L2
,
1
,
1
);
// however mini batch gradient descent parameters with slower learning rate(below) can be used to get higher accuracy than with parameters mentioned above
// LogisticRegressionParams params1 = LogisticRegressionParams(0.000001, 10, LogisticRegression::MINI_BATCH, LogisticRegression::REG_L2, 1, 1);
cout
<<
"training Logisitc Regression classifier
\n
"
<<
endl
;
LogisticRegression
lr
_
(
data_train
,
labels_train
,
params
);
lr
_
.
predict
(
data_test
,
responses
);
LogisticRegression
lr
1
(
data_train
,
labels_train
,
params1
);
lr
1
.
predict
(
data_test
,
responses
);
labels_test
.
convertTo
(
labels_test
,
CV_32S
);
cout
<<
"Original Label :: Predicted Label"
<<
endl
;
...
...
@@ -141,21 +147,24 @@ int main()
cout
<<
"saving the classifier"
<<
endl
;
// save the classfier
lr_
.
save
(
"NewLR_Trained.xml"
);
fs1
.
open
(
"NewLR_Trained.xml"
,
FileStorage
::
WRITE
);
lr1
.
write
(
fs1
);
fs1
.
release
();
// load the classifier onto new object
LogisticRegression
lr2
;
LogisticRegressionParams
params2
=
LogisticRegressionParams
();
LogisticRegression
lr2
(
params2
);
cout
<<
"loading a new classifier"
<<
endl
;
lr2
.
load
(
"NewLR_Trained.xml"
);
fs2
.
open
(
"NewLR_Trained.xml"
,
FileStorage
::
READ
);
FileNode
fn2
=
fs2
.
root
();
lr2
.
read
(
fn2
);
fs2
.
release
();
Mat
responses2
;
// predict using loaded classifier
cout
<<
"predicting the dataset using the loaded classfier
\n
"
<<
endl
;
lr2
.
predict
(
data_test
,
responses2
);
// calculate accuracy
cout
<<
"accuracy using loaded classifier: "
<<
100
*
(
float
)
cv
::
countNonZero
(
labels_test
==
responses2
)
/
responses2
.
rows
<<
"%"
<<
endl
;
waitKey
(
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment