Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bolsonaro
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Luc Giffon
bolsonaro
Commits
f9d50914
Commit
f9d50914
authored
5 years ago
by
Léo Bouscarrat
Browse files
Options
Downloads
Patches
Plain Diff
Add test for base OmpForest class
parent
a1a7f767
No related branches found
No related tags found
1 merge request
!21
Resolve "Add some tests"
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
code/bolsonaro/models/model_parameters.py
+14
-0
14 additions, 0 deletions
code/bolsonaro/models/model_parameters.py
tests/test_bolsonaro.py
+58
-0
58 additions, 0 deletions
tests/test_bolsonaro.py
with
72 additions
and
0 deletions
code/bolsonaro/models/model_parameters.py
+
14
−
0
View file @
f9d50914
...
...
@@ -7,6 +7,20 @@ class ModelParameters(object):
def
__init__
(
self
,
extracted_forest_size
,
normalize_D
,
subsets_used
,
normalize_weights
,
seed
,
hyperparameters
,
extraction_strategy
):
"""
Init of ModelParameters.
Args:
extracted_forest_size (list): list of all the extracted forest
size.
normalize_D (bool): true normalize the distribution, false no
subsets_used (list): which dataset use for randomForest and for OMP
'
train
'
,
'
dev
'
or
'
train+dev
'
and combination of two of this.
normalize_weights (bool): if we normalize the weights or no.
seed (int): the seed used for the randomization.
hyperparameters (dict): dict of the hyperparameters of RandomForest
in scikit-learn.
extraction_strategy (str): either
'
none
'
,
'
random
'
,
'
omp
'
"""
self
.
_extracted_forest_size
=
extracted_forest_size
self
.
_normalize_D
=
normalize_D
self
.
_subsets_used
=
subsets_used
...
...
This diff is collapsed.
Click to expand it.
tests/test_bolsonaro.py
0 → 100644
+
58
−
0
View file @
f9d50914
import
numpy
as
np
from
bolsonaro.models.model_parameters
import
ModelParameters
from
bolsonaro.models.omp_forest_classifier
import
OmpForestBinaryClassifier
,
OmpForestMulticlassClassifier
from
bolsonaro.models.omp_forest_regressor
import
OmpForestRegressor
def
test_binary_classif_omp
():
model_parameters
=
ModelParameters
(
1
,
False
,
[
'
train+dev
'
,
'
train+dev
'
],
False
,
1
,
{
'
n_estimators
'
:
100
},
'
omp
'
)
omp_forest
=
OmpForestBinaryClassifier
(
model_parameters
)
X_train
=
[[
1
,
0
],
[
0
,
1
]]
y_train
=
[
-
1
,
1
]
omp_forest
.
fit
(
X_train
,
y_train
,
X_train
,
y_train
)
results
=
omp_forest
.
predict
(
X_train
)
assert
isinstance
(
results
,
np
.
ndarray
)
def
test_regression_omp
():
model_parameters
=
ModelParameters
(
1
,
False
,
[
'
train+dev
'
,
'
train+dev
'
],
False
,
1
,
{
'
n_estimators
'
:
100
},
'
omp
'
)
omp_forest
=
OmpForestRegressor
(
model_parameters
)
X_train
=
[[
1
,
0
],
[
0
,
1
]]
y_train
=
[
-
1
,
1
]
omp_forest
.
fit
(
X_train
,
y_train
,
X_train
,
y_train
)
results
=
omp_forest
.
predict
(
X_train
)
assert
isinstance
(
results
,
np
.
ndarray
)
def
test_multiclassif_omp
():
model_parameters
=
ModelParameters
(
1
,
False
,
[
'
train+dev
'
,
'
train+dev
'
],
False
,
1
,
{
'
n_estimators
'
:
100
},
'
omp
'
)
omp_forest
=
OmpForestMulticlassClassifier
(
model_parameters
)
X_train
=
[[
1
,
0
],
[
0
,
1
]]
y_train
=
[
-
1
,
1
]
omp_forest
.
fit
(
X_train
,
y_train
,
X_train
,
y_train
)
results
=
omp_forest
.
predict
(
X_train
)
assert
isinstance
(
results
,
np
.
ndarray
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment