49 lines
2 KiB
Python
49 lines
2 KiB
Python
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
import seaborn as sns
|
|
|
|
|
|
def plotTestVsPredicted (df_predTest, metabs, modelname, savePath, multiple = False):
|
|
|
|
print(" ----------------- STARTING PLOTTING ----------------- ")
|
|
|
|
def plotTVP(df_predTest, metab, modelname):
|
|
plt.figure()
|
|
sns.lmplot(data = df_predTest, x=metab+"_pred", y=metab, height=7, aspect = 1)
|
|
plt.title("TEST VS PREDICTED lmplot " + metab + " " + modelname)
|
|
plt.savefig(savePath+"/testVsPredicted_lmplot_"+ metab+"_"+modelname+"_"".png")
|
|
plt.close("all")
|
|
|
|
if multiple:
|
|
for metab in metabs:
|
|
plotTVP(df_predTest=df_predTest, metab=metab, modelname=modelname)
|
|
#sns.regplot(data = pred_prueba_DF, x=metab+"_pred", y=metab+"_test", )
|
|
else:
|
|
plotTVP(df_predTest=df_predTest, metab = metabs, modelname=modelname)
|
|
#print(" ----------------- PREDICTED VS TEST " + metab + " ----------------- ")
|
|
|
|
|
|
def plotResiduals (df_predTest, metabs, modelname, savePath, multiple = False):
|
|
|
|
#for metab in metabs:
|
|
#print(" ----------------- PREDICTED VS RESIDUALS " + metab + " ----------------- ")
|
|
|
|
def plotR (df_predTest, metab, modelname):
|
|
y_pred_metab = df_predTest[metab+"_pred"]
|
|
residuals = df_predTest[metab]-df_predTest[metab+"_pred"]
|
|
df_all = pd.concat([y_pred_metab, residuals], axis=1)
|
|
df_all.columns = ["Predicted", "Residuals"]
|
|
|
|
plt.figure(figsize = [10,10])
|
|
sns.scatterplot(data = df_all, x="Predicted", y="Residuals")
|
|
plt.axhline(y=0)
|
|
plt.title("RESIDUALS VS PREDICTED " + metab + " " + modelname)
|
|
plt.savefig(savePath+"/residualsVsPredicted_"+ metab+"_"+modelname+"_"+".png")
|
|
plt.close("all")
|
|
|
|
if multiple:
|
|
for metab in metabs:
|
|
plotR(df_predTest=df_predTest, metab=metab, modelname=modelname)
|
|
else:
|
|
plotR(df_predTest=df_predTest, metab=metabs, modelname=modelname)
|
|
|