Negative Log Likelihood Calculator

Measure model uncertainty across prediction tasks. View losses, compare outputs, and interpret each sample with clear exports and graphs.

Calculator Inputs

Choose the likelihood structure for your prediction task.
Mean normalizes by sample count. Total preserves full loss mass.
Protects against log(0) during probability calculations.

Binary Classification Inputs

Use 0 and 1 values. Separate with commas or spaces.
Enter a probability for each sample between 0 and 1.
Binary NLL formula:
-Σ[y log(p) + (1-y) log(1-p)]

This mode is suited for logistic outputs, click probabilities, fraud scores, churn risk, and other Bernoulli predictions.

Example Data Table

Sample Task Type Observed Value Model Output Interpretation
1 Binary 1 0.92 High confidence and correct prediction.
2 Binary 0 0.15 Low risk estimate, matching the true class.
3 Multiclass 2 0.10, 0.20, 0.70 Class 2 receives the highest probability.
4 Gaussian 5.0 4.8 Small residual means lower Gaussian NLL.

Formula Used

1) Binary Classification

For binary targets y ∈ {0,1} and predicted probability p for class 1:

NLL = -Σ [ y log(p) + (1-y) log(1-p) ]

This punishes confident mistakes sharply. A prediction of 0.99 for the wrong class creates a much larger loss than a cautious 0.60 error.

2) Multiclass Classification

For a sample with true class probability p_true:

NLL = -Σ log(p_true)

This is the standard categorical cross-entropy form. Lower loss means the model places stronger probability mass on the correct class.

3) Gaussian Regression

For observed value y, predicted mean μ, and standard deviation σ:

NLL = 0.5 log(2πσ²) + (y-μ)² / (2σ²)

When the constant term is disabled, the calculator keeps only the squared-error likelihood component. This is useful for comparative model scoring.

How to Use This Calculator

  1. Choose the model type that matches your data: binary, multiclass, or Gaussian regression.
  2. Paste observed targets into the appropriate input field using commas, spaces, or one row per sample.
  3. Enter model probabilities or predicted means in the matching format.
  4. Set epsilon to avoid numerical issues when probabilities approach zero or one.
  5. Choose whether you want mean NLL or total NLL reported as the primary output.
  6. For Gaussian regression, enter the standard deviation and decide whether to include the constant term.
  7. Press Calculate NLL to display the result section below the header and above the form.
  8. Use the CSV and PDF buttons to export detailed per-sample contributions and summary metrics.

FAQs

1) What does negative log likelihood measure?

It measures how well predicted probabilities explain observed outcomes. Lower values mean the model assigned higher probability to what actually happened.

2) Why is lower NLL better?

Lower NLL means the true outcomes were less surprising under the model. Strong predictions on correct events reduce the loss significantly.

3) What is the difference between total and mean NLL?

Total NLL sums loss across all samples. Mean NLL divides by sample count, making comparison easier across datasets of different sizes.

4) Why do I need epsilon clamping?

Clamping prevents taking the logarithm of zero. Without it, extreme probabilities can cause undefined values or unstable numeric results.

5) Can I use this for softmax outputs?

Yes. The multiclass mode is designed for softmax-style probabilities. Each row should represent one sample with probabilities across all classes.

6) What does perplexity mean here?

Perplexity is the exponential of mean NLL. It is often used in language modeling to describe average uncertainty per sample or token.

7) Why include the Gaussian constant term?

The constant term gives the full Gaussian likelihood expression. Removing it is useful when comparing models under the same fixed variance.

8) Can this calculator help detect overconfident models?

Yes. Very large NLL values often appear when a model assigns extreme confidence to wrong predictions, revealing calibration or fit problems.

Related Calculators

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.