class_docstr: Unit test class for testing scikit-learn converter.
code: def test_random_sparse_data(self):
      n_columns = 8
      n_categories = 20
  
      import numpy.random as rn
  
      rn.seed(0)
      categories = rn.randint(50000, size=(n_columns, n_categories))
  
      for dt in ["int32", "float32", "float64"]:
          _X = np.array(
              [
                  [
                      categories[j, rn.randint(n_categories)]
                      for j in range(n_columns)
                  ]
                  for i in range(100)
              ],
              dtype=dt,
          )
  
          # Test this data on a bunch of possible inputs.
          for sparse in (True, False):
              for categorical_features in [
                  "all",
                  [3],
                  [4],
                  range(2, 8),
                  range(0, 4),
                  range(0, 8),
              ]:
                  X = _X.copy()
  
                  # This appears to be the only type now working.
                  assert X.dtype == np.dtype(dt)
  
                  model = OneHotEncoder(
                      categorical_features=categorical_features,
                      sparse=sparse,
                  )
                  model.fit(X)
  
                  # Convert the model
                  spec = sklearn.convert(
                      model, [("data", Array(n_columns))], "out"
                  )
  
                  X_out = model.transform(X)
                  if sparse:
                      X_out = X_out.todense()
  
                  input_data = [{"data": row} for row in X]
                  output_data = [{"out": row} for row in X_out]
  
                  result = evaluate_transformer(
                      spec, input_data, output_data
                  )
  
                  assert result["num_errors"] == 0
  
          # Test normal data inside a pipeline
          for sparse in (True, False):
              for categorical_features in [
                  "all",
                  [3],
                  [4],
                  range(2, 8),
                  range(0, 4),
                  range(0, 8),
              ]:
                  X = _X.copy()
  
                  model = Pipeline(
                      [
                          (
                              "OHE",
                              OneHotEncoder(
                                  categorical_features=categorical_features,
                                  sparse=sparse,
                              ),
                          ),
                          ("Normalizer", Normalizer()),
                      ]
                  )
  
                  model.fit(X)
  
                  # Convert the model
                  spec = sklearn.convert(
                      model, [("data", Array(n_columns))], "out"
                  ).get_spec()
  
                  X_out = model.transform(X)
                  if sparse:
                      X_out = X_out.todense()
  
                  input_data = [{"data": row} for row in X]
                  output_data = [{"out": row} for row in X_out]
  
                  result = evaluate_transformer(
                      spec, input_data, output_data
                  )
  
                  assert result["num_errors"] == 0
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/test/sklearn_tests/test_one_hot_encoder.py
imports: from copy import copy
  import unittest
  import numpy
  from coremltools._deps import _HAS_SKLEARN
  from coremltools.models.utils import evaluate_transformer, _macos_version, _is_macos
label_desc: Use image node_id 7 for calling the OneHotEncoderScikitTest obj's underlying member method code with example usage: obj.test_random_sparse_data() without return types