CalcWorldHub
Free online calculator · no signup

Balanced class weights calculator

Compute inverse-frequency sample weights for two classes using the balanced class-weight convention.

4,000 tools
Balanced class weights calculator — Class 0 training examples, Class 1 training examples and calculation method
Balanced class weights calculator: inputs and calculation method.

How to use this calculator

Compute inverse-frequency sample weights for two classes using the balanced class-weight convention.

  1. Enter Class 0 training examples, Class 1 training examples. Match the units shown beside each field and review the result together with the assumptions below.
  2. Read the worked example below to check the expected input format and result.
  3. Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
Data science calculation

How this calculation works

Balanced class weights give each class the same total aggregate weight when applied to its training observations. For two classes, the per-observation weight is the number of samples divided by the number of classes times that class's count.

Inputs and units

class0 — Class 0 training examples
Enter the number of training examples assigned to the first class.
class1 — Class 1 training examples
Enter the number of training examples assigned to the second class.

Formula

Displayed formula

Weight for class i = n samples ÷ (n classes × count in class i). For two classes, n classes = 2.

Method

Enter the number of training examples in each of two classes. The calculator applies the inverse-frequency formula separately and reports the effective total weight contributed by each class.

Worked example

With 900 class-0 and 100 class-1 examples, total n is 1,000. The weights are 1,000 ÷ (2 × 900) ≈ 0.5556 and 1,000 ÷ (2 × 100) = 5, so each class contributes 500 total weight units.

Assumptions and limits

This uses the two-class balanced convention without additional sample weights. It does not select a model, guarantee better performance, or account for asymmetric error costs.

Frequently asked questions

Why does the smaller class receive a larger weight per example?

Inverse-frequency weighting increases the contribution of each rarer-class example so both classes have equal aggregate weight.

Are balanced weights guaranteed to improve a model?

No. They change the training objective and may help or hurt depending on the data, model, and evaluation goal.

Does this support more than two classes?

This calculator is for two classes. For multiple classes, apply n divided by class-count times each class frequency using the full class count.

How do I use the Balanced class weights calculator?

Enter Class 0 training examples, Class 1 training examples. Match the units shown beside each field and review the result together with the assumptions below.

What is a worked example of Balanced class weights?

With 900 class-0 and 100 class-1 examples, total n is 1,000. The weights are 1,000 ÷ (2 × 900) ≈ 0.5556 and 1,000 ÷ (2 × 100) = 5, so each class contributes 500 total weight units.