Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Luc Giffon
bolsonaro
Commits
af068a00
Commit
af068a00
authored
Mar 06, 2020
by
Léo Bouscarrat
Browse files
Better to take non zero values of list as indicated in the numpy doc
parent
2d896dd1
Changes
2
Hide whitespace changes
Inline
Side-by-side
code/bolsonaro/models/omp_forest.py
View file @
af068a00
...
@@ -136,14 +136,11 @@ class SingleOmpForest(OmpForest):
...
@@ -136,14 +136,11 @@ class SingleOmpForest(OmpForest):
:param X: a Forest
:param X: a Forest
:return: a np.array of the predictions of the entire forest
:return: a np.array of the predictions of the entire forest
"""
"""
forest_predictions
=
self
.
_base_estimator
_predictions
(
X
).
T
forest_predictions
=
np
.
array
([
tree
.
predict
(
X
)
for
tree
in
self
.
_base_
forest_
estimator
.
estimators_
])
if
self
.
_models_parameters
.
normalize_D
:
if
self
.
_models_parameters
.
normalize_D
:
forest_predictions
/=
self
.
_forest_norms
forest_predictions
/=
self
.
_forest_norms
weights
=
self
.
_omp
.
coef_
weights
=
self
.
_omp
.
coef_
omp_trees_indices
=
np
.
nonzero
(
weights
)[
0
]
select_trees
=
np
.
mean
(
forest_predictions
[
weights
!=
0
],
axis
=
0
)
select_trees
=
np
.
mean
(
forest_predictions
[
omp_trees_indices
],
axis
=
0
)
print
(
len
(
omp_trees_indices
))
return
select_trees
return
select_trees
code/bolsonaro/models/omp_forest_classifier.py
View file @
af068a00
...
@@ -40,9 +40,7 @@ class OmpForestBinaryClassifier(SingleOmpForest):
...
@@ -40,9 +40,7 @@ class OmpForestBinaryClassifier(SingleOmpForest):
forest_predictions
/=
self
.
_forest_norms
forest_predictions
/=
self
.
_forest_norms
weights
=
self
.
_omp
.
coef_
weights
=
self
.
_omp
.
coef_
omp_trees_indices
=
np
.
nonzero
(
weights
)
omp_trees_predictions
=
forest_predictions
[
weights
!=
0
].
T
[
1
]
omp_trees_predictions
=
forest_predictions
[
omp_trees_indices
].
T
[
1
]
# Here forest_pred is the probability of being class 1.
# Here forest_pred is the probability of being class 1.
...
...
Write
Preview
Supports
Markdown
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