code: def feature_conductance(net, test_input_tensor):
      """
      The method takes tensor(s) of input examples (matching the forward function of the model),
      and returns the input attributions for the given input example.
      The returned values of the attribute method are the attributions,
      which match the size of the given inputs, and delta,
      which approximates the error between the approximated integral and true integral.
      This method saves the distribution of avg attributions of the trained features for the given target.
      """
      ig = IntegratedGradients(net)
      test_input_tensor.requires_grad_()
      attr, _ = ig.attribute(
          test_input_tensor, target=1, return_convergence_delta=True
      )
      attr = attr.detach().numpy()
      # To understand these attributions, we can first average them across all the inputs and print and visualize the average attribution for each feature.
      feature_imp, feature_imp_dict = visualize_importances(
          feature_names, np.mean(attr, axis=0)
      )
      mlflow.log_metrics(feature_imp_dict)
      mlflow.log_text(str(feature_imp), "feature_imp_summary.txt")
      fig, (ax1, ax2) = plt.subplots(2, 1)
      fig.tight_layout(pad=3)
      ax1.hist(attr[:, 1], 100)
      ax1.set(title="Distribution of Sibsp Attribution Values")
  
      # we can bucket the examples by the value of the sibsp feature and plot the average attribution for the feature.
      # In the plot below, the size of the dot is proportional to the number of examples with that value.
  
      bin_means, bin_edges, _ = stats.binned_statistic(
          test_features[:, 1], attr[:, 1], statistic="mean", bins=6
      )
      bin_count, _, _ = stats.binned_statistic(
          test_features[:, 1], attr[:, 1], statistic="count", bins=6
      )
  
      bin_width = bin_edges[1] - bin_edges[0]
      bin_centers = bin_edges[1:] - bin_width / 2
      ax2.scatter(bin_centers, bin_means, s=bin_count)
      ax2.set(
          xlabel="Average Sibsp Feature Value",
          ylabel="Average Attribution",
      )
      mlflow.log_figure(fig, "Average_Sibsp_Feature_Value.png")
  
imports: import os
  from argparse import ArgumentParser
  import matplotlib.pyplot
  import numpy
  import pandas
  import torch
  from captum.attr import IntegratedGradients, LayerConductance, NeuronConductance
  from prettytable import PrettyTable
  from scipy import stats
  from sklearn.model_selection import train_test_split
  from torch import nn
  import mlflow
label_desc: Use image node_id 7 for calling a global function with example usage: feature_conductance(net, test_input_tensor) without return types