class_docstr: Test Case to generate pdf report
class_docstr_tok: ["Test","Case","to","generate","pdf","report"]
code: def test_add_feature_analysis(self):
      self.name = "feature-analysis"
      self.report_name = "Feature Analysis Report"
      self.page_number = 4
      ## Create Report
      self.report = Report(name=self.report_name)
      ### Create Feature Analysis Section as new page
      self.report.detail.add_new_page()
      self.report.detail.add_section_title(
          "Example for Feature Analysis "
      )
      ### Add Header Level 1
      self.report.detail.add_header_level_1(text="Feature Analysis")
      self.assertEqual(len(self.report.detail.contents), 3)
  
      ### Add Header Level 2
      self.report.detail.add_header_level_2(text="Feature Importance")
      self.assertEqual(len(self.report.detail.contents), 4)
      ### Feature Importance
      path = Path(prepare_input_path(data_path="sample_data/model.pkl"))
      model = pd.read_pickle(str(path))
      path = Path(
          prepare_input_path(data_path="sample_data/train_data.csv")
      )
      data = pd.read_csv(str(path))
      # -- csv including header --
      feature_names = data.columns
  
      fi = FeatureInterpreter(feature_names=feature_names)
      rank = fi.get_feature_importance_ranking(
          trained_model=model, train_x=data, method="default"
      )
      self.report.detail.add_feature_importance(
          importance_ranking=rank, importance_threshold=0.005
      )
      self.assertEqual(len(self.report.detail.contents), 5)
  
      ### Create Performance Analysis Section as new page
      self.report.detail.add_new_page()
      self.report.detail.add_section_title(
          "Example for Performance Analysis "
      )
      self.report.detail.add_paragraph(
          text="this is dummy model, no trained with titanic dataset"
      )
      ### Add Header Level 1
      self.report.detail.add_header_level_1(text="Performance Analysis")
      ### Add Header Level 2
      self.report.detail.add_header_level_2(
          text="Hyperparameter Tuning"
      )
      self.assertEqual(len(self.report.detail.contents), 10)
  
      ### Hyperparameter Tuning
      with open(
          prepare_input_path(
              data_path="sample_data/hyperparameter_tuning.json"
          ),
          "r",
      ) as f:
          hyperparameter_tuning = json.load(f)
      print("search_space:", hyperparameter_tuning["search_space"])
      print("best_idx:", hyperparameter_tuning["best_idx"])
      self.assertEqual(hyperparameter_tuning["best_idx"], "3")
      print(
          "history [first 2 samples]:",
          {
              k: hyperparameter_tuning["history"][k]
              for k in list(hyperparameter_tuning["history"].keys())[:2]
          },
      )
      print(
          "benchmark_metric:", hyperparameter_tuning["benchmark_metric"]
      )
      self.assertEqual(
          hyperparameter_tuning["benchmark_metric"], "accuracy"
      )
      print(
          "benchmark_threshold:",
          hyperparameter_tuning["benchmark_threshold"],
      )
      self.assertEqual(
          hyperparameter_tuning["benchmark_threshold"], 0.8
      )
      print(
          "non_hyperopt_score:",
          hyperparameter_tuning["non_hyperopt_score"],
      )
  
      self.report.detail.add_hyperparameter_tuning(
          history=hyperparameter_tuning["history"],
          best_idx=hyperparameter_tuning["best_idx"],
          search_space=hyperparameter_tuning["search_space"],
          benchmark_metric=hyperparameter_tuning["benchmark_metric"],
          benchmark_threshold=hyperparameter_tuning[
              "benchmark_threshold"
          ],
          non_hyperopt_score=hyperparameter_tuning[
              "non_hyperopt_score"
          ],
      )
      print(self.report.detail.contents)
      self.assertEqual(len(self.report.detail.contents), 11)
  
imports: import json
  import os
  import sys
  import unittest
  from pathlib import Path
  import warnings
  import numpy
  import pandas
  from PyPDF2 import PdfFileReader
  from datetime import datetime
  from xai.data import DataUtil
  from xai.data.constants import DATATYPE
  from xai.model.interpreter import FeatureInterpreter
  from xai.formatter import Report, PdfWriter
  from tests.formatter.util import prepare_input_path, prepare_output_path
label_desc: Use image node_id 7 for calling the TestGeneratePdfReport obj's underlying member method code with example usage: obj.test_add_feature_analysis() without return types