diff --git a/Class_Mod/Miscellaneous.py b/Class_Mod/Miscellaneous.py index f3f9d512098164f518c92bc9501394a73161407b..bb7b1016ee46f7e75866a77289db8e4c21ec6df7 100644 --- a/Class_Mod/Miscellaneous.py +++ b/Class_Mod/Miscellaneous.py @@ -7,21 +7,6 @@ def local_css(file_name): st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True) local_css("style/style.css") -# Cross-Validation of the model -def CV_model(estimator, x, y, cv): - st.write('Cross-Validation of this model') - st.write("CV_scores", cross_val_score(estimator, x, y, cv=cv)) - st.write("-- CV predict --") - Y_preds = cross_val_predict(estimator, x, y, cv=3) - st.write("MAE", mean_absolute_error(y, Y_preds)) - st.write("MSE", mean_squared_error(y, Y_preds)) - st.write("MAPE", mean_absolute_percentage_error(y, Y_preds)) - st.write("R²", r2_score(y, Y_preds)) - st.write("-- Cross Validate --") - cv_results = cross_validate(estimator, x, y, cv=cv, return_train_score=True, n_jobs=3) - for key in cv_results.keys(): - st.write(key, cv_results[key]) - # predict module def prediction(NIRS_csv, qsep, qhdr, model): # hdr var correspond to column header True or False in the CSV @@ -33,3 +18,24 @@ def prediction(NIRS_csv, qsep, qhdr, model): Y_preds = model.predict(X_test) # Y_preds = X_test return Y_preds + + +def reg_plot( meas, pred): + fig, ax = plt.subplots(figsize = (12,4)) + sns.regplot(x = meas[0] , y = pred[0], color='blue', label = 'Calib') + sns.regplot(x = meas[1], y = pred[1], color='red', label = 'CV') + sns.regplot(x = meas[2], y = pred[2], color='green', label = 'Test') + plt.plot([np.min(meas[0])+0.1, np.max([meas[0]])+0.1], [np.min(meas[0])+0.1, np.max([meas[0]])+0.1], color = 'black') + ax.set_ylabel('Predicted values') + ax.set_xlabel('Measured values') + plt.legend() + plt.margins(0) + +def resid_plot( meas, pred): + fig, ax = plt.subplots(figsize = (12,4)) + sns.residplot(x = meas[0], y = pred[0], color='blue', label = 'Calib') + sns.residplot(x = meas[1], y = pred[1], color='red', label = 'CV') + sns.residplot(x = meas[2], y = pred[2], color='green', label = 'Test') + ax.set_ylabel('Residuals') + ax.set_xlabel('Predicted values') + plt.legend() \ No newline at end of file