Relevance analysis should be made into a new script
Relevance analysis is currently implemented in the predict
step of this framework with the following code:
import os
import numpy as np
from matplotlib.backends.backend_pdf import PdfPages
from ..utils.plot import relevance_analysis_plot
# Logistic regressor weights
if model.name == "logistic-regression":
logger.info("Logistic regression identified: saving model weights")
for param in model.parameters():
model_weights = np.array(param.data.reshape(-1))
break
filepath = os.path.join(output_folder, "LogReg_Weights.pdf")
logger.info(f"Creating and saving weights plot at {filepath}...")
os.makedirs(os.path.dirname(filepath), exist_ok=True)
pdf = PdfPages(filepath)
pdf.savefig(
relevance_analysis_plot(model_weights, title="LogReg model weights")
)
pdf.close()
This would be better implemented in a separate stand-alone script that can be called upon need, depending on the model being analysed (or even globally, on the analysis script itself).