Skip to content
Snippets Groups Projects
Miscellaneous.py 1.27 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")

# 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
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