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
0619630f
Commit
0619630f
authored
2 weeks ago
by
DIANE
Browse files
Options
Downloads
Patches
Plain Diff
script cleaning
parent
f319fbeb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pages/3-prediction.py
+37
-43
37 additions, 43 deletions
src/pages/3-prediction.py
with
37 additions
and
43 deletions
src/pages/3-prediction.py
+
37
−
43
View file @
0619630f
...
...
@@ -187,12 +187,6 @@ with c1:
# Load parameters
st
.
subheader
(
"
I - Spectral data preprocessing & visualization
"
,
divider
=
"
blue
"
)
if
not
pred_data
.
empty
:
# Load the model with joblib
from
utils.data_handling
import
signal_preprocess
preprocessed
=
signal_preprocess
(
np
.
array
(
pred_data
.
loc
[:,
system_data
[
"
data
"
][
"
wls
"
]]),
tune
=
system_data
[
"
spec-preprocessing
"
],
)
try
:
from
utils.data_handling
import
signal_preprocess
...
...
@@ -208,20 +202,16 @@ if not pred_data.empty: # Load the model with joblib
if
not
preprocessed
.
empty
:
c2
,
c3
=
st
.
columns
([
2
,
1
])
with
c2
:
rawspectraplot
=
plot_spectra
(
pred_data
,
color
=
None
,
cmap
=
None
,
xunits
=
"
Wavelength/Wavenumber
"
,
yunits
=
"
Signal intensity
"
,
)
prepspectraplot
=
plot_spectra
(
preprocessed
,
color
=
None
,
cmap
=
None
,
xunits
=
"
Wavelength/Wavenumber
"
,
yunits
=
"
Signal intensity
"
,
)
rawspectraplot
,
prepspectraplot
=
[
plot_spectra
(
i
,
color
=
None
,
cmap
=
None
,
xunits
=
"
Wavelength/Wavenumber
"
,
yunits
=
"
Signal intensity
"
,
)
for
i
in
(
pred_data
,
preprocessed
)
]
st
.
write
(
"
Raw spectra
"
)
st
.
pyplot
(
rawspectraplot
)
...
...
@@ -280,6 +270,7 @@ if not preprocessed.empty:
)
)
return
fig
pca
=
calpred_pca
(
cal
=
system_data
[
"
data
"
][
"
raw-spectra
"
]
.
iloc
[
system_data
[
"
data
"
][
"
idx
"
][
"
train
"
],
:]
...
...
@@ -299,7 +290,7 @@ if not preprocessed.empty:
disable2
=
False
if
not
pred_data
.
empty
else
True
pred_button
=
st
.
button
(
"
Predict
"
+
str
(
system_data
[
"
data
"
][
"
target
"
][
'
name
'
])
+
"
values
"
,
"
Predict
"
+
str
(
system_data
[
"
data
"
][
"
target
"
][
"
name
"
])
+
"
values
"
,
type
=
"
primary
"
,
disabled
=
disable2
,
use_container_width
=
False
,
...
...
@@ -308,30 +299,31 @@ if not preprocessed.empty:
st
.
session_state
[
"
predict
"
]
=
True
if
not
preprocessed
.
empty
and
st
.
session_state
[
"
predict
"
]:
model
=
system_data
[
'
model
'
][
"
model_
"
]
if
system_data
[
'
model
'
][
"
model_type
"
]
in
[
"
PLS
"
,
"
TPE-iPLS
"
]:
nvar
=
system_data
[
'
model
'
][
"
model_
"
].
n_features_in_
elif
system_data
[
'
model
'
][
"
model_type
"
]
==
"
LW-PLS
"
:
model
=
system_data
[
"
model
"
][
"
model_
"
]
if
system_data
[
"
model
"
][
"
model_type
"
]
in
[
"
PLS
"
,
"
TPE-iPLS
"
]:
nvar
=
system_data
[
"
model
"
][
"
model_
"
].
n_features_in_
elif
system_data
[
"
model
"
][
"
model_type
"
]
==
"
LW-PLS
"
:
nvar
=
system_data
[
"
data
"
][
"
raw-spectra
"
].
shape
[
1
]
if
system_data
[
'
model
'
][
"
selected-wls
"
]
is
None
:
if
system_data
[
"
model
"
][
"
selected-wls
"
]
is
None
:
preprocesseddf
=
preprocessed
else
:
preprocesseddf
=
preprocessed
.
loc
[:,
system_data
[
'
model
'
][
"
selected-wls
"
]]
preprocesseddf
=
preprocessed
.
loc
[:,
system_data
[
"
model
"
][
"
selected-wls
"
]]
if
not
preprocesseddf
.
empty
:
match
system_data
[
'
model
'
][
"
model_type
"
]:
match
system_data
[
"
model
"
][
"
model_type
"
]:
case
"
PLS
"
|
"
TPE-iPLS
"
:
if
preprocesseddf
.
shape
[
1
]
==
nvar
:
result
=
DataFrame
(
system_data
[
'
model
'
][
"
model_
"
].
predict
(
preprocesseddf
.
to_numpy
()
),
index
=
preprocesseddf
.
index
,
columns
=
[
"
Results
"
])
system_data
[
"
model
"
][
"
model_
"
].
predict
(
preprocesseddf
.
to_numpy
()
),
index
=
preprocesseddf
.
index
,
columns
=
[
"
Results
"
],
)
try
:
result
=
DataFrame
(
system_data
[
'
model
'
][
"
model_
"
].
predict
(
system_data
[
"
model
"
][
"
model_
"
].
predict
(
preprocesseddf
.
to_numpy
()
),
index
=
preprocesseddf
.
index
,
...
...
@@ -350,10 +342,11 @@ if not preprocessed.empty:
try
:
spectra
=
signal_preprocess
(
np
.
array
(
system_data
[
"
data
"
][
"
raw-spectra
"
])[
system_data
[
"
data
"
][
"
idx
"
][
'
train
'
],
:],
tune
=
system_data
[
"
spec-preprocessing
"
],
)
np
.
array
(
system_data
[
"
data
"
][
"
raw-spectra
"
])[
system_data
[
"
data
"
][
"
idx
"
][
"
train
"
],
:
],
tune
=
system_data
[
"
spec-preprocessing
"
],
)
from
utils.lwplsr_julia_converted
import
lwpls
...
...
@@ -362,10 +355,11 @@ if not preprocessed.empty:
Xtrain
=
np
.
array
(
spectra
),
Xtest
=
np
.
array
(
preprocessed
),
ytrain
=
np
.
array
(
system_data
[
"
data
"
][
"
target
"
][
'
target
'
].
iloc
[
system_data
[
"
data
"
][
"
idx
"
][
'
train
'
]
system_data
[
"
data
"
][
"
target
"
][
"
target
"
].
iloc
[
system_data
[
"
data
"
][
"
idx
"
][
"
train
"
]
]
),
**
system_data
[
'
model
'
][
'
model_
'
]
),
**
system_data
[
"
model
"
][
"
model_
"
],
),
index
=
preprocessed
.
index
,
)
...
...
@@ -432,8 +426,8 @@ if not result.empty:
st
.
dataframe
(
resultT
.
T
)
with
c5
:
st
.
info
(
"
The performance of the model used for prediction making
"
)
st
.
table
(
system_data
[
'
model
'
][
"
performance
"
])
st
.
pyplot
(
system_data
[
'
model
'
][
"
measvspred
"
])
st
.
table
(
system_data
[
"
model
"
][
"
performance
"
])
st
.
pyplot
(
system_data
[
"
model
"
][
"
measvspred
"
])
from
utils.miscellaneous
import
desc_stats
st
.
info
(
"
descriptive statistics for the model output
"
)
...
...
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