Table of Contents

Assignment: EM Algorithm

For Prior Estimation & Prior Shift Compensation

📅 Deadline: 8.1.2025 21:59

🏦 Points: 5

Task Description

In this assignment, you are tasked with implementing the EM algorithm for estimating class prior on unlabeled test data. Afterwards, you must use the estimated prior to account for prior shift in the plugin Bayes classifier. You can find the complete description of the assignment in the Assignment .

You are provided with a template containing the following files:

Your objective is to implement the function e_step which estimates p_{test}(y|x), the function m_step which estimates p_{test}(y), the function compute_test_priors which runs the EM algorithm to estimate p_{test}(y), and the function bayes_classifier_with_prior_shift which implements the plugin-bayes classifier adapted to the prior shift. All of these functions can be found in main.py.

All python files must be stored in the root of the .zip sent for submission.
The expected runtime of the evaluation is about 7 minutes.

Go make yourself a coffee while you wait.

The Bayes classifier test might fail on your machine, but still be correct. So far, we observed it in code of 1 student. It is caused by having different versions of Scikit-Learn. Jakub

Further Reading

https://arxiv.org/abs/2106.11695

How to Test

After completing your implementation, you can test your solution using the following commands before submitting it to BRUTE:


Test Case 1
python main.py test-cases/public/instances/instance_1.json --plot

Expected output:

EM Algorithm - E Step:
  e_step: Test OK
  
EM Algorithm - M Step:
  m_step: Test OK

EM Algorithm - Estimated priors:
  estimated_test_prior: Test OK

Bayes Classifier:
  risks bayes_classifier: Test OK
  
Without prior compensation; Loss: 0.13
With prior compensation; Loss: 0.09
Improvement:  0.04

Test Case 2
python main.py test-cases/public/instances/instance_2.json --plot

Expected output:

EM Algorithm - E Step:
  e_step: Test OK
  
EM Algorithm - M Step:
  m_step: Test OK

EM Algorithm - Estimated priors:
  estimated_test_prior: Test OK

Bayes Classifier:
  risks bayes_classifier: Test OK
  
Without prior compensation; Loss: 0.43
With prior compensation; Loss: 0.37
Improvement:  0.06

Test Case 3
python main.py test-cases/public/instances/instance_3.json --plot

Expected output:

EM Algorithm - E Step:
  e_step: Test OK
  
EM Algorithm - M Step:
  m_step: Test OK

EM Algorithm - Estimated priors:
  estimated_test_prior: Test OK

Bayes Classifier:
  risks bayes_classifier: Test OK
  
Without prior compensation; Loss: 0.13
With prior compensation; Loss: 0.1
Improvement:  0.03

Submission Guidelines