diff --git a/src/Class_Mod/UMAP_.py b/src/Class_Mod/UMAP_.py index 05ee5b3f11059363f73b3abe813abf12afb347fb..28d0436e6efe90fb251e60627234376cc10467d0 100644 --- a/src/Class_Mod/UMAP_.py +++ b/src/Class_Mod/UMAP_.py @@ -6,8 +6,7 @@ class Umap: """ The UMAP dimension reduction algorithm from scikit learn """ - def __init__(self, data_import, numerical_data, cat_data): - self.x = data_import + def __init__(self, numerical_data, cat_data): self.numerical_data = numerical_data if cat_data is None: self.categorical_data_encoded = cat_data @@ -21,7 +20,7 @@ class Umap: self.model = UMAP(n_neighbors=20, n_components=3, min_dist=0.0, random_state=42,) self.model.fit(self.numerical_data, y = self.categorical_data_encoded) self.scores_raw = self.model.transform(self.numerical_data) - self.scores = pd.DataFrame(self.scores_raw, index = self.x.index) + self.scores = pd.DataFrame(self.scores_raw, index = self.numerical_data.index) @property def scores_(self): diff --git a/src/pages/1-samples_selection.py b/src/pages/1-samples_selection.py index 7c24b46a9a4b9b56c18502ee3fa10b11e72a8c0a..df7d4ec20b8b021f7d45f0c6a2d83ab1978857cd 100644 --- a/src/pages/1-samples_selection.py +++ b/src/pages/1-samples_selection.py @@ -109,7 +109,7 @@ if not spectra.empty: supervised = meta_data[col] else: supervised = None - dr_model = Umap(data_import = imp, numerical_data = MinMaxScale(spectra), cat_data = supervised) + dr_model = Umap(numerical_data = MinMaxScale(spectra), cat_data = supervised) if dr_model: axis1 = pc.selectbox("x-axis", options = dr_model.scores_.columns, index=0) @@ -240,7 +240,7 @@ if not t.empty: plt.savefig("./Report/Figures/test.png") st.plotly_chart(fig, use_container_width=True) - + import plotly.express as px if labels: @@ -269,29 +269,7 @@ if not t.empty: fig_axe2_axe3.update_traces(marker=dict(size=4)) fig_axe2_axe3.write_image("./Report/Figures/plot_axe2_axe3.png") - else : - - fig_axe1_axe2 = px.scatter(tcr, x=axis1, y=axis2, color=labels if list(labels) else None) - fig_axe1_axe2.update_layout(title='Axe1-Axe2') - fig_axe1_axe2.update_traces(marker=dict(size=4)) - fig_axe1_axe2.write_image("./Report/Figures/plot_axe1_axe2.png") - - - # Créer et exporter le graphique Axe1-Axe3 en PNG - fig_axe1_axe3 = px.scatter(tcr, x=axis1, y=axis3, color=labels if list(labels) else None) - fig_axe1_axe3.update_layout(title='Axe1-Axe3') - fig_axe1_axe3.update_traces(marker=dict(size=4)) - fig_axe1_axe3.write_image("./Report/Figures/plot_axe1_axe3.png") - - - # Créer et exporter le graphique Axe2-Axe3 en PNG - fig_axe2_axe3 = px.scatter(tcr, x=axis2, y=axis3, color=labels if list(labels) else None) - fig_axe2_axe3.update_layout(title='Axe2-Axe3') - fig_axe2_axe3.update_traces(marker=dict(size=4)) - fig_axe2_axe3.write_image("./Report/Figures/plot_axe2_axe3.png") - -################################################################# if not spectra.empty: if dim_red_method == dim_red_methods[1]: diff --git a/src/pages/2-model_creation.py b/src/pages/2-model_creation.py index e83931ea53a0309b63756ca9818117bd46ae64db..996302ad78e801c5b6a606064699e0ea878f3a9b 100644 --- a/src/pages/2-model_creation.py +++ b/src/pages/2-model_creation.py @@ -19,10 +19,8 @@ st.session_state["interface"] = st.session_state.get('interface') if st.session_state["interface"] == 'simple': hide_pages("Predictions") -######################################################################################## -reg_algo = ["","Full-PLSR", "Locally Weighted PLSR", "Interval-PLSR", "Full-PLSR-sklearn", "PrePLStester"] -# page Design + ####################################### page Design ####################################### st.header("Calibration Model Development", divider='blue') st.write("Create a predictive model, then use it for predicting your target variable (chemical values) from NIRS spectra") M1, M2, M3 = st.columns([2,3,2]) @@ -35,12 +33,15 @@ M7.write('Predicted vs Measured values') M8.write('Residuals plot') M9, M10 = st.columns([2,2]) M9.write("-- Save the model --") + ###################################################################### + +reg_algo = ["","Full-PLSR", "Locally Weighted PLSR", "Interval-PLSR", "Full-PLSR-sklearn", "PrePLStester"] + ####################################### ########################################### files_format = ['.csv', '.dx'] file = M3.radio('select data file format:', options = files_format) - ### Data spectra = pd.DataFrame y = pd.DataFrame @@ -57,14 +58,11 @@ if file == files_format[0]: else: col = False ycal_csv = M3.file_uploader("Select corresponding Chemical Data", type="csv", help=" :mushroom: select a csv matrix with samples as rows and chemical values as a column") - - if ycal_csv: sepy = M3.radio("separator (Y file): ", options=[";", ","], key=2) hdry = M3.radio("samples name (Y file)?: ", options=["no", "yes"], key=3) if hdry == "yes": col = 0 else: col = False - if xcal_csv and ycal_csv: spectra, meta_data = col_cat(pd.read_csv(xcal_csv, decimal='.', sep=sepx, index_col=col, header=0)) @@ -77,13 +75,11 @@ if file == files_format[0]: if spectra.shape[0] == y.shape[0]: pass + else: M3.warning('The number of samples is different in X and Y') y = pd.DataFrame spectra = pd.DataFrame - - - ## Load .dx file elif file == files_format[1]: @@ -94,10 +90,13 @@ elif file == files_format[1]: tmp_path = tmp.name chem_data, spectra, meta_data = read_dx(file = tmp_path) M3.success("The data have been loaded successfully", icon="✅") - yname = M3.selectbox('Select target', options=chem_data.columns) - measured = chem_data.loc[:,yname] > 0 - y = chem_data.loc[:,yname].loc[measured] - spectra = spectra.loc[measured] + if chem_data.shape[1]>0: + yname = M3.selectbox('Select target', options=chem_data.columns) + measured = chem_data.loc[:,yname] > 0 + y = chem_data.loc[:,yname].loc[measured] + spectra = spectra.loc[measured] + else: + M3.warning('Warning: Chemical data are not included in your file !', icon="âš ï¸") os.unlink(tmp_path) ### split the data