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
a9eda16e
Commit
a9eda16e
authored
6 months ago
by
DIANE
Browse files
Options
Downloads
Patches
Plain Diff
all issues were handled
parent
4047ea1d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Class_Mod/RegModels.py
+25
-30
25 additions, 30 deletions
src/Class_Mod/RegModels.py
src/pages/1-samples_selection.py
+2
-2
2 additions, 2 deletions
src/pages/1-samples_selection.py
src/pages/2-model_creation.py
+245
-212
245 additions, 212 deletions
src/pages/2-model_creation.py
with
272 additions
and
244 deletions
src/Class_Mod/RegModels.py
+
25
−
30
View file @
a9eda16e
...
@@ -93,8 +93,8 @@ class Regmodel(object):
...
@@ -93,8 +93,8 @@ class Regmodel(object):
########################################### PLSR #########################################
########################################### PLSR #########################################
class
Plsr
(
Regmodel
):
class
Plsr
(
Regmodel
):
def
__init__
(
self
,
train
,
test
,
n_iter
=
10
):
def
__init__
(
self
,
train
,
test
,
n_iter
=
10
,
nfolds
=
3
):
super
().
__init__
(
train
,
test
,
n_iter
,
add_hyperparams
=
{
'
n_components
'
:
hp
.
randint
(
'
n_components
'
,
2
,
20
)})
super
().
__init__
(
train
,
test
,
n_iter
,
nfolds
=
nfolds
,
add_hyperparams
=
{
'
n_components
'
:
hp
.
randint
(
'
n_components
'
,
1
,
20
)})
### parameters in common
### parameters in common
def
objective
(
self
,
params
):
def
objective
(
self
,
params
):
...
@@ -114,14 +114,9 @@ class Plsr(Regmodel):
...
@@ -114,14 +114,9 @@ class Plsr(Regmodel):
params
[
'
deriv
'
],
params
[
'
polyorder
'
],
params
[
'
window_length
'
]
=
a
,
b
,
c
params
[
'
deriv
'
],
params
[
'
polyorder
'
],
params
[
'
window_length
'
]
=
a
,
b
,
c
x2
=
[
savgol_filter
(
x1
[
i
],
polyorder
=
params
[
'
polyorder
'
],
deriv
=
params
[
'
deriv
'
],
window_length
=
params
[
'
window_length
'
])
for
i
in
range
(
2
)]
x2
=
[
savgol_filter
(
x1
[
i
],
polyorder
=
params
[
'
polyorder
'
],
deriv
=
params
[
'
deriv
'
],
window_length
=
params
[
'
window_length
'
])
for
i
in
range
(
2
)]
Model
=
PLSRegression
(
scale
=
False
,
n_components
=
params
[
'
n_components
'
])
model
=
PLSRegression
(
scale
=
False
,
n_components
=
params
[
'
n_components
'
])
# self._cv_df = KF_CV().process(model = Model, x = x2[0], y = self._ytrain, n_folds = self._nfolds)
# self._cv_df['Average'] = self._cv_df.mean(axis = 1)
# self._cv_df['S'] = self._cv_df.std(axis = 1)
# self._cv_df['CV(%)'] = self._cv_df['S'] * 100 / self._cv_df['Average']
# self._cv_df = self._cv_df.T.round(2)
folds
=
KF_CV
().
CV
(
x
=
x2
[
0
],
y
=
np
.
array
(
self
.
_ytrain
),
n_folds
=
self
.
_nfolds
)
folds
=
KF_CV
().
CV
(
x
=
x2
[
0
],
y
=
np
.
array
(
self
.
_ytrain
),
n_folds
=
self
.
_nfolds
)
yp
=
KF_CV
().
cross_val_predictor
(
model
=
M
odel
,
folds
=
folds
,
x
=
x2
[
0
],
y
=
np
.
array
(
self
.
_ytrain
))
yp
=
KF_CV
().
cross_val_predictor
(
model
=
m
odel
,
folds
=
folds
,
x
=
x2
[
0
],
y
=
np
.
array
(
self
.
_ytrain
))
self
.
_cv_df
=
KF_CV
().
metrics_cv
(
y
=
np
.
array
(
self
.
_ytrain
),
ypcv
=
yp
,
folds
=
folds
)[
1
]
self
.
_cv_df
=
KF_CV
().
metrics_cv
(
y
=
np
.
array
(
self
.
_ytrain
),
ypcv
=
yp
,
folds
=
folds
)[
1
]
score
=
self
.
_cv_df
.
loc
[
"
cv
"
,
'
rmse
'
]
score
=
self
.
_cv_df
.
loc
[
"
cv
"
,
'
rmse
'
]
...
@@ -147,15 +142,15 @@ class Plsr(Regmodel):
...
@@ -147,15 +142,15 @@ class Plsr(Regmodel):
############################################ iplsr #########################################
############################################ iplsr #########################################
class
TpeIpls
(
Regmodel
):
class
TpeIpls
(
Regmodel
):
def
__init__
(
self
,
train
,
test
,
n_iter
=
10
,
n_intervall
=
5
):
def
__init__
(
self
,
train
,
test
,
n_iter
=
10
,
n_intervall
=
5
,
nfolds
=
3
):
self
.
n_intervall
=
n_intervall
self
.
n_intervall
=
n_intervall
self
.
n_arrets
=
self
.
n_intervall
*
2
self
.
n_arrets
=
self
.
n_intervall
*
2
r
=
{
'
n_components
'
:
hp
.
randint
(
'
n_components
'
,
2
,
1
0
)}
r
=
{
'
n_components
'
:
hp
.
randint
(
'
n_components
'
,
1
,
2
0
)}
r
.
update
({
f
'
v
{
i
}
'
:
hp
.
randint
(
f
'
v
{
i
}
'
,
0
,
train
[
0
].
shape
[
1
])
for
i
in
range
(
1
,
self
.
n_arrets
+
1
)})
r
.
update
({
f
'
v
{
i
}
'
:
hp
.
randint
(
f
'
v
{
i
}
'
,
0
,
train
[
0
].
shape
[
1
])
for
i
in
range
(
1
,
self
.
n_arrets
+
1
)})
super
().
__init__
(
train
,
test
,
n_iter
,
add_hyperparams
=
r
)
super
().
__init__
(
train
,
test
,
n_iter
,
add_hyperparams
=
r
,
nfolds
=
nfolds
)
### parameters in common
### parameters in common
...
@@ -166,7 +161,7 @@ class TpeIpls(Regmodel):
...
@@ -166,7 +161,7 @@ class TpeIpls(Regmodel):
arrays
=
[
np
.
arange
(
self
.
idx
[
2
*
i
],
self
.
idx
[
2
*
i
+
1
]
+
1
)
for
i
in
range
(
self
.
n_intervall
)]
arrays
=
[
np
.
arange
(
self
.
idx
[
2
*
i
],
self
.
idx
[
2
*
i
+
1
]
+
1
)
for
i
in
range
(
self
.
n_intervall
)]
id
=
np
.
unique
(
np
.
concatenate
(
arrays
,
axis
=
0
),
axis
=
0
)
id
=
np
.
unique
(
np
.
concatenate
(
arrays
,
axis
=
0
),
axis
=
0
)
#
## Preprocessing
### Preprocessing
x0
=
[
self
.
_xc
,
self
.
_xt
]
x0
=
[
self
.
_xc
,
self
.
_xt
]
x1
=
[
eval
(
str
(
params
[
'
normalization
'
])
+
"
(x0[i])
"
)
for
i
in
range
(
2
)]
x1
=
[
eval
(
str
(
params
[
'
normalization
'
])
+
"
(x0[i])
"
)
for
i
in
range
(
2
)]
...
@@ -180,35 +175,35 @@ class TpeIpls(Regmodel):
...
@@ -180,35 +175,35 @@ class TpeIpls(Regmodel):
params
[
'
deriv
'
],
params
[
'
polyorder
'
],
params
[
'
window_length
'
]
=
a
,
b
,
c
params
[
'
deriv
'
],
params
[
'
polyorder
'
],
params
[
'
window_length
'
]
=
a
,
b
,
c
x2
=
[
savgol_filter
(
x1
[
i
],
polyorder
=
params
[
'
polyorder
'
],
deriv
=
params
[
'
deriv
'
],
window_length
=
params
[
'
window_length
'
])
for
i
in
range
(
2
)]
x2
=
[
savgol_filter
(
x1
[
i
],
polyorder
=
params
[
'
polyorder
'
],
deriv
=
params
[
'
deriv
'
],
window_length
=
params
[
'
window_length
'
])
for
i
in
range
(
2
)]
# print(x2)
# ## Modelling
folds
=
KF_CV
().
CV
(
x
=
x2
[
0
],
y
=
np
.
array
(
self
.
_ytrain
),
n_folds
=
self
.
_nfolds
)
prepared_data
=
[
x2
[
i
][:,
id
]
for
i
in
range
(
2
)]
### Modelling
folds
=
KF_CV
().
CV
(
x
=
prepared_data
[
0
],
y
=
np
.
array
(
self
.
_ytrain
),
n_folds
=
self
.
_nfolds
)
try
:
try
:
model
=
PLSRegression
(
scale
=
False
,
n_components
=
params
[
'
n_components
'
])
Model
=
PLSRegression
(
scale
=
False
,
n_components
=
params
[
'
n_components
'
])
yp
=
KF_CV
().
cross_val_predictor
(
model
=
model
,
folds
=
folds
,
x
=
prepared_data
[
0
],
y
=
np
.
array
(
self
.
_ytrain
))
yp
=
KF_CV
().
cross_val_predictor
(
model
=
Model
,
folds
=
folds
,
x
=
x2
[
0
],
y
=
np
.
array
(
self
.
_ytrain
))
self
.
_cv_df
=
KF_CV
().
metrics_cv
(
y
=
np
.
array
(
self
.
_ytrain
),
ypcv
=
yp
,
folds
=
folds
)[
1
]
self
.
_cv_df
=
KF_CV
().
metrics_cv
(
y
=
np
.
array
(
self
.
_ytrain
),
ypcv
=
yp
,
folds
=
folds
)[
1
]
except
ValueError
as
ve
:
except
ValueError
as
ve
:
Model
=
PLSRegression
(
scale
=
False
,
n_components
=
1
)
params
[
"
n_components
"
]
=
1
params
[
"
n_components
"
]
=
1
yp
=
KF_CV
().
cross_val_predictor
(
model
=
Model
,
folds
=
folds
,
x
=
x2
[
0
],
y
=
np
.
array
(
self
.
_ytrain
))
model
=
PLSRegression
(
scale
=
False
,
n_components
=
params
[
"
n_components
"
])
yp
=
KF_CV
().
cross_val_predictor
(
model
=
model
,
folds
=
folds
,
x
=
prepared_data
[
0
],
y
=
np
.
array
(
self
.
_ytrain
))
self
.
_cv_df
=
KF_CV
().
metrics_cv
(
y
=
np
.
array
(
self
.
_ytrain
),
ypcv
=
yp
,
folds
=
folds
)[
1
]
self
.
_cv_df
=
KF_CV
().
metrics_cv
(
y
=
np
.
array
(
self
.
_ytrain
),
ypcv
=
yp
,
folds
=
folds
)[
1
]
# self._cv_df['Average'] = self._cv_df.mean(axis = 1)
# self._cv_df['S'] = self._cv_df.std(axis = 1)
# self._cv_df['CV(%)'] = self._cv_df['S'] * 100 / self._cv_df['Average']
# self._cv_df = self._cv_df.T.round(2)
score
=
self
.
_cv_df
.
loc
[
'
cv
'
,
'
rmse
'
]
score
=
self
.
_cv_df
.
loc
[
'
cv
'
,
'
rmse
'
]
Model
=
PLSRegression
(
scale
=
False
,
n_components
=
params
[
'
n_components
'
]
)
Model
=
PLSRegression
(
scale
=
False
,
n_components
=
model
.
n_components
)
Model
.
fit
(
x2
[
0
][:,
id
],
self
.
_ytrain
)
Model
.
fit
(
prepared_data
[
0
],
self
.
_ytrain
)
if
self
.
SCORE
>
score
:
if
self
.
SCORE
>
score
:
self
.
SCORE
=
score
self
.
SCORE
=
score
self
.
_ycv
=
KF_CV
().
meas_pred_eq
(
y
=
np
.
array
(
self
.
_ytrain
),
ypcv
=
yp
,
folds
=
folds
)
self
.
_ycv
=
KF_CV
().
meas_pred_eq
(
y
=
np
.
array
(
self
.
_ytrain
),
ypcv
=
yp
,
folds
=
folds
)
self
.
_yc
=
Model
.
predict
(
x2
[
0
][:,
id
])
self
.
_yc
=
Model
.
predict
(
prepared_data
[
0
])
self
.
_yt
=
Model
.
predict
(
x2
[
1
][:,
id
])
self
.
_yt
=
Model
.
predict
(
prepared_data
[
1
])
self
.
_model
=
Model
self
.
_model
=
Model
for
key
,
value
in
params
.
items
():
for
key
,
value
in
params
.
items
():
try
:
params
[
key
]
=
int
(
value
)
try
:
params
[
key
]
=
int
(
value
)
...
@@ -231,4 +226,4 @@ class TpeIpls(Regmodel):
...
@@ -231,4 +226,4 @@ class TpeIpls(Regmodel):
class
Pcr
(
Regmodel
):
class
Pcr
(
Regmodel
):
def
__init__
(
self
,
train
,
test
,
n_iter
=
10
,
n_val
=
5
):
def
__init__
(
self
,
train
,
test
,
n_iter
=
10
,
n_val
=
5
):
super
.
__init__
()
super
.
__init__
()
{
f
'
pc
{
i
}
'
:
hp
.
randint
(
f
'
pc
{
i
+
1
}
'
,
0
,
train
[
0
].
shape
[
1
])
for
i
in
range
(
self
.
n_val
)}
{
f
'
pc
{
i
}
'
:
hp
.
randint
(
f
'
pc
{
i
+
1
}
'
,
0
,
train
[
0
].
shape
[
1
])
for
i
in
range
(
self
.
n_val
)}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/pages/1-samples_selection.py
+
2
−
2
View file @
a9eda16e
...
@@ -658,6 +658,6 @@ if not sam.empty:
...
@@ -658,6 +658,6 @@ if not sam.empty:
zipname
=
json
.
load
(
f
)
zipname
=
json
.
load
(
f
)
if
os
.
path
.
split
(
recent_file
)[
1
]
==
os
.
path
.
split
(
zipname
)[
1
]:
if
os
.
path
.
split
(
recent_file
)[
1
]
==
os
.
path
.
split
(
zipname
)[
1
]:
with
open
(
"
./temp/
"
+
zipname
,
"
rb
"
)
as
fp
:
with
open
(
"
./temp/
"
+
zipname
,
"
rb
"
)
as
fp
:
st
.
write
(
'
Download the Analysis Results
'
)
st
.
subheader
(
'
Download the Analysis Results
'
)
st
.
download_button
(
'
Download
'
,
data
=
fp
,
file_name
=
zipname
,
mime
=
"
application/zip
"
,
st
.
download_button
(
'
Download
'
,
data
=
fp
,
file_name
=
zipname
,
mime
=
"
application/zip
"
,
args
=
None
,
kwargs
=
None
,
type
=
"
primary
"
,
use_container_width
=
True
)
args
=
None
,
kwargs
=
None
,
type
=
"
primary
"
,
use_container_width
=
True
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/pages/2-model_creation.py
+
245
−
212
View file @
a9eda16e
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