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
3a2ec5cb
Commit
3a2ec5cb
authored
5 years ago
by
Charly Lamothe
Browse files
Options
Downloads
Patches
Plain Diff
Fix score func in trainer
parent
6239030f
No related branches found
No related tags found
1 merge request
!9
Resolve "Experiment pipeline"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
code/bolsonaro/trainer.py
+10
-13
10 additions, 13 deletions
code/bolsonaro/trainer.py
with
10 additions
and
13 deletions
code/bolsonaro/trainer.py
+
10
−
13
View file @
3a2ec5cb
...
@@ -51,7 +51,8 @@ class Trainer(object):
...
@@ -51,7 +51,8 @@ class Trainer(object):
def
train
(
self
,
model
):
def
train
(
self
,
model
):
"""
"""
:param model: Object with
:param model: An instance of either RandomForestRegressor, RandomForestClassifier, OmpForestRegressor,
OmpForestBinaryClassifier, OmpForestMulticlassClassifier.
:return:
:return:
"""
"""
...
@@ -72,32 +73,28 @@ class Trainer(object):
...
@@ -72,32 +73,28 @@ class Trainer(object):
self
.
_end_time
=
time
.
time
()
self
.
_end_time
=
time
.
time
()
def
__score_func
(
self
,
model
,
X
,
y_true
):
def
__score_func
(
self
,
model
,
X
,
y_true
):
if
type
(
model
)
==
OmpForestRegressor
:
if
type
(
model
)
in
[
OmpForestRegressor
,
RandomForestRegressor
]
:
y_pred
=
model
.
predict
(
X
)
y_pred
=
model
.
predict
(
X
)
result
=
mean_squared_error
(
y_true
,
y_pred
)
result
=
mean_squared_error
(
y_true
,
y_pred
)
elif
type
(
model
)
in
[
OmpForestBinaryClassifier
,
OmpForestMulticlassClassifier
,
RandomForestClassifier
]:
elif
type
(
model
)
in
[
OmpForestBinaryClassifier
,
OmpForestMulticlassClassifier
]:
y_pred
=
model
.
predict
(
X
)
y_pred
=
model
.
predict
(
X
)
result
=
accuracy_score
(
y_true
,
y_pred
)
result
=
accuracy_score
(
y_true
,
y_pred
)
else
:
y_pred
=
model
.
predict
(
X
)
result
=
model
.
score
(
y_true
,
y_pred
)
return
result
return
result
def
__score_func_base
(
self
,
model
,
X
,
y_true
):
def
__score_func_base
(
self
,
model
,
X
,
y_true
):
if
type
(
model
)
==
OmpForestRegressor
:
if
type
(
model
)
==
OmpForestRegressor
:
y_pred
=
model
.
predict_base_estimator
(
X
)
y_pred
=
model
.
predict_base_estimator
(
X
)
result
=
mean_squared_error
(
y_true
,
y_pred
)
result
=
mean_squared_error
(
y_true
,
y_pred
)
elif
type
(
model
)
in
[
OmpForestBinaryClassifier
,
OmpForestMulticlassClassifier
]:
elif
type
(
model
)
in
[
OmpForestBinaryClassifier
,
OmpForestMulticlassClassifier
]:
y_pred
=
model
.
predict_base_estimator
(
X
)
y_pred
=
model
.
predict_base_estimator
(
X
)
result
=
accuracy_score
(
y_true
,
y_pred
)
result
=
accuracy_score
(
y_true
,
y_pred
)
elif
type
(
model
)
==
RandomForestClassifier
:
else
:
y_pred
=
model
.
predict
(
X
)
y_pred
=
model
.
predict_base_estimator
(
X
)
result
=
accuracy_score
(
y_true
,
y_pred
)
result
=
model
.
score
(
y_true
,
y_pred
)
elif
type
(
model
)
==
RandomForestRegressor
:
y_pred
=
model
.
predict
(
X
)
result
=
mean_squared_error
(
y_true
,
y_pred
)
return
result
return
result
...
...
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