code: def test_tree_variance(
      tree: _FanovaTree, expected_tree_statistics: List[Dict[str, List]]
  ) -> None:
      # The root node at node index `0` holds the values and weights for all nodes in the tree.
      expected_statistics = expected_tree_statistics[0]
      expected_values = expected_statistics["values"]
      expected_weights = expected_statistics["weights"]
      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(tree.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 3 for calling a global function with example usage: test_tree_variance(tree, expected_tree_statistics) without return types