View source: R/DiscreteLearning.R
| probDiscreteVariable | R Documentation |
Compute the probabilities of a discrete variable from a data set using Laplace correction.
probDiscreteVariable(x)
x |
a |
Laplace correction is used to avoid the zero probability problem, with \alpha = 1 as smoothing factor.
Therefore, the probability for each state, \theta_i, is computed as
\theta_i = \frac{x_i + 1}{N + K}
for i = 0, 1, \ldots, K,
where x_i is the number of records of state i,
N is the total number of records, and
K is the total number of states.
A list of 2 elements:
coeff |
a named vector that contains the probabilities. |
sizeDataLeaf |
a vector containing the number of records in each leaf of the discrete tree. |
discreteVariablesStates
## Simulate discrete variable
x <- factor(sample(c('yes', 'no', 'maybe'), 500, replace = TRUE),
levels = c('yes', 'no', 'maybe'))
## Compute probabilities
p <- probDiscreteVariable(x)
p
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.