Skip to content
Snippets Groups Projects
Miscellaneous.py 1.49 KiB
Newer Older
DIANE's avatar
DIANE committed
from Packages import *
    
# local CSS
## load the custom CSS in the style folder
def local_css(file_name):
    with open(file_name) as f:
        st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
local_css("style/style.css")

# predict module
def prediction(NIRS_csv, qsep, qhdr, model):
    # hdr var correspond to column header True or False in the CSV
    if qhdr == 'yes':
        col = 0
    else:
        col = False
    X_test = pd.read_csv(NIRS_csv, sep=qsep, index_col=col)
    Y_preds = model.predict(X_test)
    # Y_preds = X_test
    return Y_preds
DIANE's avatar
DIANE committed


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()