Skip to content
Snippets Groups Projects
Commit 2cd400f0 authored by DIANE's avatar DIANE
Browse files

preprocessed spectra plot visualization + report

parent 6ec8e4c7
No related branches found
No related tags found
No related merge requests found
...@@ -340,9 +340,16 @@ def report(*args): ...@@ -340,9 +340,16 @@ def report(*args):
\label{fig:importance} \label{fig:importance}
\end{figure} \end{figure}
""" """
elif "LW-PLS" in to_report:
elif "LW-PLS " in to_report: latex_report += r"""The average of raw and preprocessed spectra is visualized in \cref{fig:importance}. \par
""""""
\begin{figure}[h]
\centering
\includegraphics[width=1\linewidth]{Variable_importance.png}
\caption{Visualizing the average spectrum computed for raw and preprocessed spectra}
\label{fig:importance}
\end{figure}
"""
elif "TPE-iPLS" in to_report: elif "TPE-iPLS" in to_report:
latex_report += r""" latex_report += r"""
Many research papers have proved that interval selection methods, with different number of intervalls, helps reduce noise and model overfitting, Many research papers have proved that interval selection methods, with different number of intervalls, helps reduce noise and model overfitting,
......
...@@ -186,8 +186,8 @@ if not spectra.empty and not y.empty: ...@@ -186,8 +186,8 @@ if not spectra.empty and not y.empty:
#M2.dataframe(Pin.pred_data_) #M2.dataframe(Pin.pred_data_)
elif regression_algo == reg_algo[2]: elif regression_algo == reg_algo[2]:
M1.write('KFold for Cross-Validation = ' + str(nb_folds)) M20.write(f'K-Fold for Cross-Validation (K = {str(nb_folds)})')
info = M1.info('Starting LWPLSR model creation... Please wait a few minutes.') info = M20.info('Starting LWPLSR model creation... Please wait a few minutes.')
# export data to csv for Julia train/test # export data to csv for Julia train/test
data_to_work_with = ['x_train_np', 'y_train_np', 'x_test_np', 'y_test_np'] data_to_work_with = ['x_train_np', 'y_train_np', 'x_test_np', 'y_test_np']
x_train_np, y_train_np, x_test_np, y_test_np = X_train.to_numpy(), y_train.to_numpy(), X_test.to_numpy(), y_test.to_numpy() x_train_np, y_train_np, x_test_np, y_test_np = X_train.to_numpy(), y_train.to_numpy(), X_test.to_numpy(), y_test.to_numpy()
...@@ -260,14 +260,15 @@ if not spectra.empty and not y.empty: ...@@ -260,14 +260,15 @@ if not spectra.empty and not y.empty:
## plots ## plots
Reg.cv_data_ = KF_CV().meas_pred_eq(y = np.array(y_train), ypcv= Reg.cv_data_['YpredCV'], folds=folds) Reg.cv_data_ = KF_CV().meas_pred_eq(y = np.array(y_train), ypcv= Reg.cv_data_['YpredCV'], folds=folds)
Reg.pretreated_spectra_ = preReg.pretreated_spectra_ Reg.pretreated_spectra_ = preReg.pretreated_spectra_
Reg.best_hyperparams_print = {**preReg.best_hyperparams_, **Reg.best_hyperparams_} Reg.best_hyperparams_print = {**preReg.best_hyperparams_, **Reg.best_hyperparams_}
Reg.best_hyperparams_ = {**preReg.best_hyperparams_, **Reg.best_hyperparams_} Reg.best_hyperparams_ = {**preReg.best_hyperparams_, **Reg.best_hyperparams_}
info.empty() info.empty()
M1.success('Model created!') M20.success('Model created!')
except FileNotFoundError as e: except FileNotFoundError as e:
# Display error message on the interface if modeling is wrong # Display error message on the interface if modeling is wrong
info.empty() info.empty()
M1.warning('- ERROR during model creation -') M20.warning('- ERROR during model creation -')
Reg = None Reg = None
for i in data_to_work_with: os.unlink(temp_path / str(i + ".csv")) for i in data_to_work_with: os.unlink(temp_path / str(i + ".csv"))
...@@ -481,8 +482,8 @@ if not spectra.empty and not y.empty and regression_algo: ...@@ -481,8 +482,8 @@ if not spectra.empty and not y.empty and regression_algo:
if regression_algo in reg_algo[1:] and Reg is not None: if regression_algo in reg_algo[1:] and Reg is not None:
fig, (ax1, ax2) = plt.subplots(2,1, figsize = (12, 4), sharex=True) fig, (ax1, ax2) = plt.subplots(2,1, figsize = (12, 4), sharex=True)
ax1.plot(colnames, np.mean(X_train, axis = 0), color = 'black', label = 'Average spectrum (Raw)') ax1.plot(colnames, np.mean(X_train, axis = 0), color = 'black', label = 'Average spectrum (Raw)')
if regression_algo != reg_algo[2]: # if regression_algo != reg_algo[2]:
ax2.plot(colnames, np.mean(Reg.pretreated_spectra_ , axis = 0), color = 'black', label = 'Average spectrum (pretreated)') ax2.plot(colnames, np.mean(Reg.pretreated_spectra_ , axis = 0), color = 'black', label = 'Average spectrum (Pretreated)')
ax2.set_xlabel('Wavelenghts') ax2.set_xlabel('Wavelenghts')
plt.tight_layout() plt.tight_layout()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment