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
f9d50914
Commit
f9d50914
authored
Mar 11, 2020
by
Léo Bouscarrat
Browse files
Add test for base OmpForest class
parent
a1a7f767
Changes
2
Hide whitespace changes
Inline
Side-by-side
code/bolsonaro/models/model_parameters.py
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
...
...
tests/test_bolsonaro.py
0 → 100644
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
)
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