DiscreteTypeProcessor.setDiscretizationParameters
- DiscreteTypeProcessor.setDiscretizationParameters(variableName, method, parameters=None)
Sets the discretization parameters for a variable. If variableName is None, sets the default parameters.
- Parameters:
variableName (
str) – the name of the variable you want to set the discretization parameters of. Set to None to set the new default.method (
str) – The method of discretization used for this variable. Use “NoDiscretization” if you do not want to discretize this variable. Possible values are: ‘NoDiscretization’, ‘quantile’, ‘uniform’, ‘kmeans’, ‘NML’, ‘CAIM’, ‘MDLP’ and ‘expert’parameters (
Any) – Each method of discretization has a parameter that can be set. - ‘quantile’: the number of bins - ‘kmeans’, ‘uniform’: the number of bins. The parameter can also be set to the string ‘elbowMethod’ so that the best number of bins is found automatically. - ‘NML’: this parameter sets the the maximum number of bins up to which the NML algorithm searches for the optimal number of bins. - ‘MDLP’, ‘CAIM’: this parameter is ignored - ‘expert’: this parameter is the set of ticks proposed by the expert. The discretized variable will set the flag ‘empirical’ which means that if the values found in the data are not in the proposed intervals, they did not raise any exception but are nevertheless accepted (as belonging to the smallest or biggest interval). - ‘NoDiscretization’: this parameter is a superset of the values for the variable found in the database (or None).
- Return type:
None
Example
import numpy as np
import pandas as pd
from pyagrum.lib.discreteTypeProcessor import DiscreteTypeProcessor
rng = np.random.default_rng(42)
X = pd.DataFrame({"x1": rng.normal(size=200), "x2": rng.integers(0, 3, size=200)})
dtp = DiscreteTypeProcessor(defaultDiscretizationMethod="uniform", defaultNumberOfBins=3)
dtp.setDiscretizationParameters("x1", "quantile", 5)
bn = dtp.discretizedTemplate(X)
bn.variable("x1").domainSize()
# 5
Class