code: def test_qda_regularization():
      # The default is reg_param=0. and will cause issues when there is a
      # constant variable.
  
      # Fitting on data with constant variable triggers an UserWarning.
      collinear_msg = "Variables are collinear"
      clf = QuadraticDiscriminantAnalysis()
      with pytest.warns(UserWarning, match=collinear_msg):
          y_pred = clf.fit(X2, y6)
  
      # XXX: RuntimeWarning is also raised at predict time because of divisions
      # by zero when the model is fit with a constant feature and without
      # regularization: should this be considered a bug? Either by the fit-time
      # message more informative, raising and exception instead of a warning in
      # this case or somehow changing predict to avoid division by zero.
      with pytest.warns(RuntimeWarning, match="divide by zero"):
          y_pred = clf.predict(X2)
      assert np.any(y_pred != y6)
  
      # Adding a little regularization fixes the division by zero at predict
      # time. But UserWarning will persist at fit time.
      clf = QuadraticDiscriminantAnalysis(reg_param=0.01)
      with pytest.warns(UserWarning, match=collinear_msg):
          clf.fit(X2, y6)
      y_pred = clf.predict(X2)
      assert_array_equal(y_pred, y6)
  
      # UserWarning should also be there for the n_samples_in_a_class <
      # n_features case.
      clf = QuadraticDiscriminantAnalysis(reg_param=0.1)
      with pytest.warns(UserWarning, match=collinear_msg):
          clf.fit(X5, y5)
      y_pred5 = clf.predict(X5)
      assert_array_equal(y_pred5, y5)
  
imports: import numpy
  import pytest
  from scipy import linalg
  from sklearn.cluster import KMeans
  from sklearn.covariance import LedoitWolf, ShrunkCovariance, ledoit_wolf
  from sklearn.datasets import make_blobs
  from sklearn.discriminant_analysis import LinearDiscriminantAnalysis, QuadraticDiscriminantAnalysis, _cov
  from sklearn.preprocessing import StandardScaler
  from sklearn.utils import _IS_WASM, check_random_state
  from sklearn.utils._testing import _convert_container, assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal
label_desc: Use image node_id 20 for calling a global function with example usage: test_qda_regularization() without return types