code: def test_tree_get_marginal_variance(
      tree: _FanovaTree,
      features: List[int],
      expected: List[
          Tuple[List[Size], List[Tuple[NodeIndex, Cardinality]]]
      ],
      expected_tree_statistics: List[Dict[str, List]],
  ) -> None:
      variance = tree.get_marginal_variance(numpy.array(features))
  
      expected_values = []
      expected_weights = []
  
      for sizes, node_indices_and_corrections in expected:
          expected_split_values = []
          expected_split_weights = []
  
          for node_index, cardinality in node_indices_and_corrections:
              expected_statistics = expected_tree_statistics[node_index]
  
              expected_split_values.append(
                  expected_statistics["values"]
              )
              expected_split_weights.append(
                  [
                      w / cardinality
                      for w in expected_statistics["weights"]
                  ]
              )
  
          expected_value = numpy.average(
              expected_split_values, weights=expected_split_weights
          )
          expected_weight = numpy.prod(
              numpy.array(sizes) * numpy.sum(expected_split_weights)
          )
          expected_values.append(expected_value)
          expected_weights.append(expected_weight)
  
      expected_average_value = numpy.average(
          expected_values, weights=expected_weights
      )
      expected_variance = numpy.average(
          (expected_values - expected_average_value) ** 2,
          weights=expected_weights,
      )
  
      assert math.isclose(variance, expected_variance)
  
file_path: optuna/tests/importance_tests/fanova_tests/test_tree.py
imports: import math
  from typing import Dict
  from typing import List
  from typing import Tuple
  from unittest.mock import Mock
  import numpy
  import pytest
  from optuna.importance._fanova._tree import _FanovaTree
label_desc: Use image node_id 4 for calling a global function with example usage: test_tree_get_marginal_variance(tree, features, expected, expected_tree_statistics) without return types