diff --git a/src/Class_Mod/Miscellaneous.py b/src/Class_Mod/Miscellaneous.py index c597b539464535e03128beb43a0611ed4f3f840e..cdf6b6296d833c4c861fa6073481e603d8e6f977 100644 --- a/src/Class_Mod/Miscellaneous.py +++ b/src/Class_Mod/Miscellaneous.py @@ -55,6 +55,7 @@ def reg_plot( meas, pred, train_idx, test_idx): ax.set_xlabel('Measured values') plt.legend() plt.margins(0) + return fig @st.cache_data def resid_plot( meas, pred, train_idx, test_idx): @@ -93,6 +94,7 @@ def resid_plot( meas, pred, train_idx, test_idx): ax.set_xlabel('Measured values') plt.legend() plt.margins(0) + return fig diff --git a/src/Report/report.log b/src/Report/report.log index 1f4d23173a639f273421380dc27c2109d5e49005..4225c0b85eaad3a14fbb019130787c3b82ac841d 100644 --- a/src/Report/report.log +++ b/src/Report/report.log @@ -1,4 +1,4 @@ -This is pdfTeX, Version 3.141592653-2.6-1.40.25 (MiKTeX 24.1) (preloaded format=pdflatex 2024.5.6) 3 JUN 2024 09:38 +This is pdfTeX, Version 3.141592653-2.6-1.40.25 (MiKTeX 24.1) (preloaded format=pdflatex 2024.5.6) 3 JUN 2024 16:22 entering extended mode restricted \write18 enabled. %&-line parsing enabled. diff --git a/src/Report/report.py b/src/Report/report.py index d26eafa39606e76972773e999c2e1c3f22e7b05a..00ea16008930254da8b4f5efb95e24844d97b8d7 100644 --- a/src/Report/report.py +++ b/src/Report/report.py @@ -65,13 +65,104 @@ def report(*args): """ if 'model' in to_report: - latex_report += r"""\noindent - \textbf{QUERY: } You asked for Model creation. - Specify bibliographic refs \cite{scikit-learn} to describe the algorithms used.\\ - \noindent - \textbf{INPUTS:} Specify here input file names \& parameters. + latex_report += r"""\subsection*{Data Visualization} + + Here we have a sub-heading. There is no blank line after the sub-heading. You can have one level of subheadings but not a third i.e. you cannot have Section 1.1.1 as a subheading. + \begin{center} + Spectral Data Visualization + \end{center} + + \begin{figure}[ht] + \centering + \includegraphics[width=1\linewidth]{""" + to_report[1] + r"""} + \label{fig:votre_graphique} + \end{figure} + \textbf{Exploratory Data Analysis-Multivariable Data Analysis} + \begin{figure}[ht] + \centering + \includegraphics[width=1\linewidth]{""" + to_report[2] + r"""} + \label{fig:votre_graphique} + \end{figure} + + """ + + # Ajout de la conversion DataFrame en LaTeX + latex_report += r""" + \begin{center} + """ + df0.to_latex(escape=True) + r""" + \end{center} + """ + + latex_report += r""" + + + After a list, you must leave a single blank line and remember to add the indent if you are starting a new paragraph. + \begin{center} + II - Model creation + \end{center} + """ + if 'full_plsr' in to_report: + latex_report += r""" + Model Choisi : Full Plsr + -- Spectral preprocessing info -- + """ + latex_report += r""" + \begin{center} + """ + df1.to_latex(escape=True) + r""" + \end{center} + """ + latex_report += r""" + Model performance + """ + latex_report += r""" + \begin{center} + """ + df2.to_latex(escape=True) + r""" + \end{center} + """ + latex_report += r""" + \newpage + Cross Validation + \begin{figure}[ht] + \centering + \includegraphics[width=0.9\linewidth]{""" + to_report[3] + r"""} + \label{fig:votre_graphique} + \end{figure} + After a list, you must leave a single blank line and remember to add the indent if you are starting a new paragraph. + After a list, you must leave a single blank line and remember to add the indent if you are starting a new paragraph. + -- Cross-Validation Summary-- """ + latex_report += r""" + \begin{center} + """ + df3.to_latex(escape=True) + r""" + \end{center} + -- Out-of-Fold Predictions Visualization (All in one) -- + \begin{figure}[ht] + \centering + \includegraphics[width=0.9\linewidth]{""" + to_report[4] + r"""} + \label{fig:votre_graphique} + \end{figure} + + III - Model Diagnosis + \begin{figure}[h] + \centering + \begin{minipage}[b]{0.5\linewidth} + \centering + \includegraphics[width=1.2\linewidth]{""" + to_report[5] + r"""} + \end{minipage}% + \begin{minipage}[b]{0.5\linewidth} + \centering + \includegraphics[width=1.2\linewidth]{""" + to_report[6] + r"""} + \end{minipage}% + \caption{\label{fig:frog}PCA} + \end{figure} + + """ + + + + + if 'predict' in to_report: latex_report += r"""\noindent diff --git a/src/Report/texput.log b/src/Report/texput.log new file mode 100644 index 0000000000000000000000000000000000000000..e3dbbcf39a3ee7016981fb36c48cfb26ab142231 --- /dev/null +++ b/src/Report/texput.log @@ -0,0 +1,21 @@ +This is pdfTeX, Version 3.141592653-2.6-1.40.25 (MiKTeX 24.1) (preloaded format=pdflatex 2024.5.6) 3 JUN 2024 13:24 +entering extended mode + restricted \write18 enabled. + %&-line parsing enabled. +** + +! Emergency stop. +<*> + +End of file on the terminal! + + +Here is how much of TeX's memory you used: + 0 strings out of 474485 + 1 string characters out of 5742319 + 1924542 words of memory out of 5000000 + 22394 multiletter control sequences out of 15000+600000 + 558069 words of font info for 36 fonts, out of 8000000 for 9000 + 1141 hyphenation exceptions out of 8191 + 0i,0n,0p,1b,6s stack positions out of 10000i,1000n,20000p,200000b,200000s +! ==> Fatal error occurred, no output PDF file produced! diff --git a/src/data/models/model__2024_06_03__created_on_Xcal_and_Ycal_data_.pkl b/src/data/models/model__2024_06_03__created_on_Xcal_and_Ycal_data_.pkl new file mode 100644 index 0000000000000000000000000000000000000000..4de067e6ad6ed7e2af1344c9bbdd50020877ee0a Binary files /dev/null and b/src/data/models/model__2024_06_03__created_on_Xcal_and_Ycal_data_.pkl differ diff --git a/src/data/params/Preprocessing.json b/src/data/params/Preprocessing.json index 1933af5f1153ab1fa70bd8697f0df56e216bf65e..2862b4a3366d05534f6c0f7fb2b77bc3ecde0e78 100644 --- a/src/data/params/Preprocessing.json +++ b/src/data/params/Preprocessing.json @@ -1 +1 @@ -{"Scatter": "Snv", "Saitzky-Golay derivative parameters": {"polyorder": 1, "deriv": 0, "window_length": 15}} \ No newline at end of file +{"deriv": 1, "n_components": \ No newline at end of file diff --git a/src/form_data.json b/src/form_data.json new file mode 100644 index 0000000000000000000000000000000000000000..d53ad6fd77167794b213e4bacb16327ab2458e39 --- /dev/null +++ b/src/form_data.json @@ -0,0 +1 @@ +{"meta_project": "Life of Brian", "meta_sample_species": "Life of Brian", "meta_sample_category": "Soil", "meta_sample_pretreatment": "Powder", "meta_machine_ID": "Life of Brian", "meta_sample_sub_category": "Green leave", "meta_sample_humidity": "Dry", "meta_scan_place": "Pace"} \ No newline at end of file diff --git a/src/pages/2-model_creation.py b/src/pages/2-model_creation.py index 54ee0f94bf398a2486f5197dce26dce07c1403f0..45b37a0707955c4bde5b76f82471ac03be7e29d6 100644 --- a/src/pages/2-model_creation.py +++ b/src/pages/2-model_creation.py @@ -131,8 +131,8 @@ if not spectra.empty and not y.empty: ax1.set_ylabel('Signal intensity') ax1.margins(0) plt.tight_layout() - M0.pyplot(fig) - + M0.pyplot(fig) ######## Loaded graph + fig.savefig("./Report/figures/Spectre_mod.png") fig, ax2 = plt.subplots(figsize = (12,3)) sns.histplot(y, color="deeppink", kde = True,label="y",ax = ax2, fill=True) sns.histplot(y_train, color="blue", kde = True,label="y (train)",ax = ax2, fill=True) @@ -142,10 +142,12 @@ if not spectra.empty and not y.empty: plt.tight_layout() M0.pyplot(fig) + fig.savefig("./Report/figures/histo.png") M0.write('Loaded data summary') M0.write(pd.DataFrame([desc_stats(y_train),desc_stats(y_test),desc_stats(y)], index =['Train', 'Test', 'Total'] ).round(2)) + LoDaSum=pd.DataFrame([desc_stats(y_train),desc_stats(y_test),desc_stats(y)], index =['Train', 'Test', 'Total'] ).round(2) ####################################### Insight into the loaded data ####################################### @@ -220,43 +222,55 @@ if not spectra.empty and not y.empty: if regression_algo in reg_algo[1:]: cv2.write('-- Cross-Validation Summary--') cv2.write(Reg.CV_results_) + cv99=pd.DataFrame(Reg.CV_results_) cv2.write('-- Out-of-Fold Predictions Visualization (All in one) --') fig1 = px.scatter(Reg.cv_data_[2], x ='Measured', y = 'Predicted' , trendline='ols', color='Folds', symbol="Folds", color_discrete_sequence=px.colors.qualitative.G10) fig1.add_shape(type='line', x0 = .95 * min(Reg.cv_data_[2].loc[:,'Measured']), x1 = 1.05 * max(Reg.cv_data_[2].loc[:,'Measured']), y0 = .95 * min(Reg.cv_data_[2].loc[:,'Measured']), y1 = 1.05 * max(Reg.cv_data_[2].loc[:,'Measured']), line = dict(color='black', dash = "dash")) fig1.update_traces(marker_size=7, showlegend=False) - + fig1.write_image("./Report/figures/Allinone.png") + cv2.plotly_chart(fig1) - fig0 = px.scatter(Reg.cv_data_[2], x ='Measured', y = 'Predicted' , trendline='ols', color='Folds', symbol="Folds", facet_col = 'Folds',facet_col_wrap=1, - color_discrete_sequence=px.colors.qualitative.G10, text='index', width=800, height=1000) + fig0 = px.scatter(Reg.cv_data_[2], x='Measured', y='Predicted', trendline='ols', color='Folds', symbol="Folds", facet_col='Folds', facet_col_wrap=1, + color_discrete_sequence=px.colors.qualitative.G10, text='index', width=800, height=1000) fig0.update_traces(marker_size=8, showlegend=False) - cv1.write('-- Out-of-Fold Predictions Visualization (Separate plots) --') + cv1.write('-- Visualisation des prédictions hors échantillon (Graphiques séparés) --') cv1.plotly_chart(fig0) - + fig0.write_image("./Report/figures/Predictions_V.png") + + yc = Reg.pred_data_[0] yt = Reg.pred_data_[1] #if M2.write('-- Spectral preprocessing info --') M2.write(Reg.best_hyperparams) - with open("data/params/Preprocessing.json", "w") as outfile: - json.dump(Reg.best_hyperparams, outfile) + json_sp = pd.DataFrame([Reg.best_hyperparams]) + + # with open("data/params/Preprocessing.json", "w") as outfile: + # json.dump(Reg.best_hyperparams, outfile) M2.write("-- Model performance --") M2.dataframe(metrics(c = [y_train, yc], t = [y_test, yt], method='regression').scores_) + model_per=pd.DataFrame(metrics(c = [y_train, yc], t = [y_test, yt], method='regression').scores_) #from st_circular_progress import CircularProgress #my_circular_progress = CircularProgress(label = 'Performance',value = 50, key = 'my performance', # size = "medium", track_color = "black", color = "blue") #my_circular_progress.st_circular_progress() #my_circular_progress.update_value(progress=20) + a=reg_plot([y_train, y_test],[yc, yt], train_idx = train_index, test_idx = test_index) + + M7.pyplot(a) + plt.savefig('./Report/figures/Predictedvs.png') + + residual_plot = resid_plot([y_train, y_test], [yc, yt], train_idx=train_index, test_idx=test_index) + M8.pyplot(residual_plot) + plt.savefig('./Report/figures/residual_plot.png') - M7.pyplot(reg_plot([y_train, y_test],[yc, yt], train_idx = train_index, test_idx = test_index)) - M8.pyplot(resid_plot([y_train, y_test],[yc, yt], train_idx = train_index, test_idx = test_index)) - # rega = Reg.important_features_ ##### ADD FEATURES IMPORTANCE PLOT #model_export = M1.selectbox("Choose way to export", options=["pickle", "joblib"], key=20) @@ -303,4 +317,16 @@ if not spectra.empty and not y.empty: ) st.page_link('pages\\3-prediction.py', label = 'Keep on keepin\' on to predict your values !') -## Load .dx file \ No newline at end of file +## Load .dx file +Ac_Km = ['histo.png', 'Spectre_mod.png','Predictions_V.png','Allinone.png','Predictedvs.png','residual_plot.png'] +with st.container(): + header3, header4 = st.columns(2) + if header3.button("Exporter le RR"): + if regression_algo == reg_algo[1]: + latex_report = report.report(LoDaSum, 'model',Ac_Km,json_sp,model_per,'full_plsr',cv99) + report.compile_latex() + else: + pass + + else: + pass \ No newline at end of file diff --git a/src/pages/3-prediction.py b/src/pages/3-prediction.py index aef7c05b0dc1b4bb90bc8d7f3cd7573f973fe77b..2f515438326e5483d76a429e84cfbdbcbbacbb6c 100644 --- a/src/pages/3-prediction.py +++ b/src/pages/3-prediction.py @@ -163,4 +163,6 @@ if loaded_model: # export to local drive - Download download_results(export_folder + export_name + '.csv', export_name + '.csv') # create a report with information on the prediction - ## see https://stackoverflow.com/a/59578663 \ No newline at end of file + ## see https://stackoverflow.com/a/59578663 + + diff --git a/src/resid_plot.png b/src/resid_plot.png new file mode 100644 index 0000000000000000000000000000000000000000..30a9d9cb6cb5b18ae8eaee8db3215b6deb8384f9 Binary files /dev/null and b/src/resid_plot.png differ