Skip to content
Snippets Groups Projects
Commit 084f7d2d authored by DIANE's avatar DIANE
Browse files

Miscellaneous update

parent 4154ce32
No related branches found
No related tags found
No related merge requests found
...@@ -7,21 +7,6 @@ def local_css(file_name): ...@@ -7,21 +7,6 @@ def local_css(file_name):
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True) st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
local_css("style/style.css") 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("", 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 # predict module
def prediction(NIRS_csv, qsep, qhdr, model): def prediction(NIRS_csv, qsep, qhdr, model):
# hdr var correspond to column header True or False in the CSV # hdr var correspond to column header True or False in the CSV
...@@ -33,3 +18,24 @@ def prediction(NIRS_csv, qsep, qhdr, model): ...@@ -33,3 +18,24 @@ def prediction(NIRS_csv, qsep, qhdr, model):
Y_preds = model.predict(X_test) Y_preds = model.predict(X_test)
# Y_preds = X_test # Y_preds = X_test
return Y_preds 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
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