Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NIRS_Workflow
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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CEFE
PACE
NIRS_Workflow
Commits
8954c365
Commit
8954c365
authored
11 months ago
by
DIANE
Browse files
Options
Downloads
Patches
Plain Diff
metrics update
parent
fa5863ce
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Class_Mod/Regression_metrics.py
+34
-106
34 additions, 106 deletions
Class_Mod/Regression_metrics.py
with
34 additions
and
106 deletions
Class_Mod/Regression_metrics.py
+
34
−
106
View file @
8954c365
from
Packages
import
*
def
metrics
(
train
,
cv
=
None
,
test
=
None
):
C
=
pd
.
DataFrame
()
CV
=
pd
.
DataFrame
()
T
=
pd
.
DataFrame
()
if
train
is
not
None
and
cv
is
not
None
and
test
is
not
None
:
C
[
"
r
"
]
=
[
np
.
corrcoef
(
train
[
0
],
train
[
1
])[
0
,
1
]]
C
[
"
r2
"
]
=
[
r2_score
(
train
[
0
],
train
[
1
])]
C
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
train
[
0
],
train
[
1
]))]
C
[
"
mae
"
]
=
[
mean_absolute_error
(
train
[
0
],
train
[
1
])]
C
.
index
=
[
'
perf
'
]
METRICS
=
C
CV
[
"
r
"
]
=
[
np
.
corrcoef
(
cv
[
0
],
cv
[
1
])[
0
,
1
]]
CV
[
"
r2
"
]
=
[
r2_score
(
cv
[
0
],
cv
[
1
])]
CV
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
cv
[
0
],
cv
[
1
]))]
CV
[
"
mae
"
]
=
[
mean_absolute_error
(
cv
[
0
],
cv
[
1
])]
CV
.
index
=
[
'
perf
'
]
T
[
"
r
"
]
=
[
np
.
corrcoef
(
test
[
0
],
test
[
1
])[
0
,
1
]]
T
[
"
r2
"
]
=
[
r2_score
(
test
[
0
],
test
[
1
])]
T
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
test
[
0
],
test
[
1
]))]
T
[
"
mae
"
]
=
[
mean_absolute_error
(
test
[
0
],
test
[
1
])]
T
.
index
=
[
'
perf
'
]
METRICS
=
pd
.
concat
([
C
,
CV
,
T
],
axis
=
1
)
elif
train
is
not
None
and
cv
is
not
None
and
test
is
None
:
C
[
"
r
"
]
=
[
np
.
corrcoef
(
train
[
0
],
train
[
1
])[
0
,
1
]]
C
[
"
r2
"
]
=
[
r2_score
(
train
[
0
],
train
[
1
])]
C
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
train
[
0
],
train
[
1
]))]
C
[
"
mae
"
]
=
[
mean_absolute_error
(
train
[
0
],
train
[
1
])]
C
.
index
=
[
'
perf
'
]
CV
[
"
r
"
]
=
[
np
.
corrcoef
(
cv
[
0
],
cv
[
1
])[
0
,
1
]]
CV
[
"
r2
"
]
=
[
r2_score
(
cv
[
0
],
cv
[
1
])]
CV
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
cv
[
0
],
cv
[
1
]))]
CV
[
"
mae
"
]
=
[
mean_absolute_error
(
cv
[
0
],
cv
[
1
])]
CV
.
index
=
[
'
perf
'
]
METRICS
=
pd
.
concat
([
C
,
CV
],
axis
=
1
)
elif
train
is
not
None
and
cv
is
None
and
test
is
not
None
:
C
[
"
r
"
]
=
[
np
.
corrcoef
(
train
[
0
],
train
[
1
])[
0
,
1
]]
C
[
"
r2
"
]
=
[
r2_score
(
train
[
0
],
train
[
1
])]
C
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
train
[
0
],
train
[
1
]))]
C
[
"
mae
"
]
=
[
mean_absolute_error
(
train
[
0
],
train
[
1
])]
C
.
index
=
[
'
perf
'
]
T
[
"
r
"
]
=
[
np
.
corrcoef
(
test
[
0
],
test
[
1
])[
0
,
1
]]
T
[
"
r2
"
]
=
[
r2_score
(
test
[
0
],
test
[
1
])]
T
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
test
[
0
],
test
[
1
]))]
T
[
"
mae
"
]
=
[
mean_absolute_error
(
test
[
0
],
test
[
1
])]
T
.
index
=
[
'
perf
'
]
METRICS
=
pd
.
concat
([
C
,
T
],
axis
=
1
)
elif
train
is
None
and
cv
is
not
None
and
test
is
not
None
:
CV
[
"
r
"
]
=
[
np
.
corrcoef
(
cv
[
0
],
cv
[
1
])[
0
,
1
]]
CV
[
"
r2
"
]
=
[
r2_score
(
cv
[
0
],
cv
[
1
])]
CV
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
cv
[
0
],
cv
[
1
]))]
CV
[
"
mae
"
]
=
[
mean_absolute_error
(
cv
[
0
],
cv
[
1
])]
CV
.
index
=
[
'
perf
'
]
T
[
"
r
"
]
=
[
np
.
corrcoef
(
test
[
0
],
test
[
1
])[
0
,
1
]]
T
[
"
r2
"
]
=
[
r2_score
(
test
[
0
],
test
[
1
])]
T
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
test
[
0
],
test
[
1
]))]
T
[
"
mae
"
]
=
[
mean_absolute_error
(
test
[
0
],
test
[
1
])]
T
.
index
=
[
'
perf
'
]
METRICS
=
pd
.
concat
([
CV
,
T
],
axis
=
1
)
elif
train
is
not
None
and
cv
is
None
and
test
is
None
:
C
[
"
r
"
]
=
[
np
.
corrcoef
(
train
[
0
],
train
[
1
])[
0
,
1
]]
C
[
"
r2
"
]
=
[
r2_score
(
train
[
0
],
train
[
1
])]
C
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
train
[
0
],
train
[
1
]))]
C
[
"
mae
"
]
=
[
mean_absolute_error
(
train
[
0
],
train
[
1
])]
C
.
index
=
[
'
perf
'
]
METRICS
=
C
if
train
is
None
and
cv
is
not
None
and
test
is
None
:
CV
[
"
r
"
]
=
[
np
.
corrcoef
(
cv
[
0
],
cv
[
1
])[
0
,
1
]]
CV
[
"
r2
"
]
=
[
r2_score
(
cv
[
0
],
cv
[
1
])]
CV
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
cv
[
0
],
cv
[
1
]))]
CV
[
"
mae
"
]
=
[
mean_absolute_error
(
cv
[
0
],
cv
[
1
])]
CV
.
index
=
[
'
perf
'
]
METRICS
=
CV
if
train
is
None
and
cv
is
None
and
test
is
not
None
:
T
[
"
r
"
]
=
[
np
.
corrcoef
(
test
[
0
],
test
[
1
])[
0
,
1
]]
T
[
"
r2
"
]
=
[
r2_score
(
test
[
0
],
test
[
1
])]
T
[
"
rmse
"
]
=
[
np
.
sqrt
(
mean_squared_error
(
test
[
0
],
test
[
1
]))]
T
[
"
mae
"
]
=
[
mean_absolute_error
(
test
[
0
],
test
[
1
])]
T
.
index
=
[
'
perf
'
]
METRICS
=
T
return
METRICS
class
metrics
:
def
__init__
(
self
,
meas
,
pred
):
if
isinstance
(
meas
,
pd
.
DataFrame
):
self
.
meas
=
meas
.
to_numpy
()
else
:
self
.
meas
=
meas
.
ravel
()
self
.
pred
=
pred
.
to_numpy
().
ravel
()
@property
def
evaluate_
(
self
):
xbar
=
np
.
mean
(
self
.
meas
)
# the average of measured values
e2
=
(
self
.
meas
-
self
.
pred
)
**
2
# the squared error
print
(
xbar
)
# Sum of squared:
# TOTAL
sst
=
np
.
sum
((
self
.
meas
-
xbar
)
**
2
)
# RESIDUAL
ssr
=
np
.
sum
(
e2
)
# REGRESSION OR MODEL
ssm
=
np
.
sum
(
self
.
pred
-
xbar
)
# Compute statistical metrics
metr
=
pd
.
DataFrame
()
metr
[
'
r
'
]
=
[
np
.
corrcoef
(
self
.
meas
.
ravel
(),
self
.
pred
)[
0
,
1
]]
metr
[
'
r2
'
]
=
[
1
-
ssr
/
sst
]
metr
[
'
rmse
'
]
=
[
np
.
sqrt
(
np
.
mean
(
e2
))]
metr
[
'
mae
'
]
=
[
np
.
mean
(
np
.
abs
(
e2
))]
metr
[
'
rpd
'
]
=
[
np
.
std
(
self
.
meas
)
/
np
.
sqrt
(
np
.
mean
(
e2
))]
metr
[
'
rpiq
'
]
=
[(
np
.
quantile
(
self
.
meas
,.
75
)
-
np
.
quantile
(
self
.
meas
,.
25
))
/
np
.
sqrt
(
np
.
mean
(
e2
))]
return
metr
\ No newline at end of file
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