-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample1.py
46 lines (38 loc) · 1.45 KB
/
example1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# SPDX-FileCopyrightText: 2025 Nikos Tsakiridis <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
from importlib import resources
import pandas
from spectraxai.dataset import Dataset, DatasetSplit
from spectraxai.spectra import SpectralPreprocessing
from spectraxai.models import Model, StandardModel
DATA_FOLDER = "spectraxai.data"
with resources.path(DATA_FOLDER, "SSL_GR.csv") as p:
df = pandas.read_csv(p)
dataset = Dataset(df.loc[:, "350":"2500":20], df.OM)
idx_trn, idx_tst = dataset.train_test_split(DatasetSplit.CROSS_VALIDATION, 5)
methods = [
SpectralPreprocessing.NONE,
SpectralPreprocessing.ABS,
[
SpectralPreprocessing.ABS,
(SpectralPreprocessing.SG1, {"window_length": 31, "polyorder": 3}),
],
[SpectralPreprocessing.ABS, SpectralPreprocessing.SNV],
[
SpectralPreprocessing.ABS,
(SpectralPreprocessing.SG1, {"window_length": 51, "polyorder": 3}),
SpectralPreprocessing.SNV,
],
[
SpectralPreprocessing.ABS,
(SpectralPreprocessing.SG2, {"window_length": 51, "polyorder": 3}),
],
[
SpectralPreprocessing.NONE,
(SpectralPreprocessing.SG1, {"window_length": 51, "polyorder": 3}),
],
[SpectralPreprocessing.NONE, SpectralPreprocessing.SNV],
]
res = StandardModel(Model.PLS).fit_and_predict_multiple(dataset, methods, idx_trn)
print(res[["pre_process", "fold", "RMSE", "R2", "RPIQ"]])