Uncertainty in Machine Learning
Author: Asim Kadav
Modeling uncertainty in predictions
There are two most common types of uncertainties in model training:
- Epistemic uncertainty refers to the uncertainty due to lack of knowledge. This is the kind of uncertainty that can be reduced by collecting more data. In Bayesian models, epistemic uncertainty is captured in the prior and posterior distributions over model parameters. A wide distribution reflects high uncertainty about the parameters, while a narrow distribution reflects high certainty.
- Aleatoric uncertainty refers to the inherent randomness or variability in the data or process being modeled. This is the kind of uncertainty that cannot be reduced by collecting more data, because it's due to inherent randomness rather than lack of knowledge. In Bayesian models, aleatoric uncertainty is typically captured by the likelihood function, which models the noise or variability in the data.
- Frequentist Methods (such as Linear Regression, Logistic Regression, SVM, etc.): These methods typically only model aleatoric uncertainty indirectly through assumptions about the noise in the data (such as assuming the residuals follow a Gaussian distribution in linear regression), but they do not model epistemic uncertainty.
- Bayesian Methods (like Bayesian Linear Regression, Gaussian Processes, etc.): As mentioned earlier, Bayesian methods are able to model both aleatoric uncertainty (via the likelihood function) and epistemic uncertainty (via the prior/posterior distributions).
- Ensemble Methods (like Random Forest, Gradient Boosting): These methods can capture a form of epistemic uncertainty by creating a diverse set of models and looking at the spread of their predictions, but they do not explicitly model aleatoric uncertainty.
- Deep Learning Methods: Traditional deep learning methods do not explicitly model either type of uncertainty. However, there are variants that do, such as Bayesian Neural Networks (which model epistemic uncertainty via distributions over weights) and models with heteroscedasticity (which model aleatoric uncertainty by letting the network learn the noise level).There is also Monte Carlo dropout that uses dropout at test time to capture uncertainties.
- Monte Carlo Methods (like MCTS, Particle Filters): These methods can capture a form of epistemic uncertainty by running many simulations and observing the spread of results, but they do not explicitly model aleatoric uncertainty.
- Reinforcement Learning: Traditional RL methods do not explicitly model either type of uncertainty, but there are variants that use Bayesian methods or ensembles to model epistemic uncertainty. Modeling aleatoric uncertainty is more challenging in RL, but can potentially be done via careful design of the reward function or use of Bayesian methods.
Click to expand Python Code for generating above plot
# Define a function to generate synthetic data
def generate_data(n_samples, noise_level, random_state=None):
np.random.seed(random_state)
X = np.linspace(-5, 5, n_samples)
y = 3 * X + np.random.normal(0, noise_level, n_samples)
return X, y
# Generate synthetic data
n_samples = 100
noise_level = 3
X, y = generate_data(n_samples, noise_level, random_state=42)
# Fit a linear regression model (Frequentist)
lr = LinearRegression()
lr.fit(X.reshape(-1, 1), y)
y_pred_lr = lr.predict(X.reshape(-1, 1))
# Fit a Gradient Boosting model (Ensemble)
gbr = GradientBoostingRegressor(n_estimators=100, random_state=42)
gbr.fit(X.reshape(-1, 1), y)
y_pred_gbr = gbr.predict(X.reshape(-1, 1))
# Plot the results
plt.figure(figsize=(14, 7))
plt.subplot(1, 2, 1)
plt.scatter(X, y, color='blue', label='Data')
plt.plot(X, y_pred_lr, color='red', label='Linear Regression')
plt.fill_between(X, y_pred_lr - noise_level, y_pred_lr + noise_level, color='red', alpha=0.1)
plt.title('Frequentist: Linear Regression')
plt.legend()
plt.subplot(1, 2, 2)
plt.scatter(X, y, color='blue', label='Data')
plt.plot(X, y_pred_gbr, color='green', label='Gradient Boosting Regressor')
plt.fill_between(X, y_pred_gbr - noise_level, y_pred_gbr + noise_level, color='green', alpha=0.1)
plt.title('Ensemble: Gradient Boosting Regressor')
plt.legend()
plt.show()
Here is the plot for an ensemble of decision trees: - The observed data points are shown in blue. - The mean prediction of the ensemble is shown in red. - The red shaded area represents the epistemic uncertainty, which is estimated as the standard deviation of the predictions of the individual trees in the ensemble. As you can see, the ensemble is able to capture the non-linearities in the data, and the spread of the individual trees' predictions gives us a measure of the epistemic uncertainty. However, as mentioned before, ensemble methods like this do not directly model aleatoric uncertainty.
- References
[1] Attend and Interact: Higher-Order Object Interactions for Video Understanding. Chih-Yao Ma, Asim Kadav, Iain Melvin, Zsolt Kira, Ghassan AlRegib, and Hans Peter Graf. In CVPR, 2018.
[2] Tripping Through Time: Efficient Localization of Activities in Videos. (Spotlight) Meera Hahn, Asim Kadav, James M. Rehg, Hans Peter Graf. In CVPR Workshop on Language and Vision, 2019. Also, appears in BMVC'20.