<jupyter_start><jupyter_text>Osnabrück University - Machine Learning (Summer Term 2018) - Prof. Dr.-Ing. <NAME>, <NAME>  Exercise Sheet 11  IntroductionThis week's sheet should be solved and handed in before the end of **Sunday, June 24, 2018**. If you need help (and Google and other resources were not enough), feel free to contact your groups' designated tutor or whomever of us you run into first. Please upload your results to your group's Stud.IP folder.  Assignment 1: Uncertainty and probability [6 Points]This exercise will focus on concepts introduced in the first part of lecture (ML-11).  a) Modeling uncertaintyIn the lecture it is claimed that probabilities can summarize several factors:1. missing knowledge1. incapability to devise complete models of complex domains1. chanceThink of an example for each of these points and explain how probabilities can be applied in modeling your example.  b) Inference by enumerationGiven the full joint distribution below, calculate the following:|         |  toothache  catch|   ¬catch |   ¬toothache  catch |  ¬catch ||:--------|-------------------------:|--------------------------:|--------------------------:|---------------------------:|| cavity  |                    0.108 |                     0.012 |                     0.072 |                      0.008 || ¬cavity |                    0.016 |                     0.064 |                     0.144 |                      0.576 |1. $P(\neg toothache)$1. $P(cavity)$1. $P(toothache \mid cavity)$1. $P(cavity \mid toothache \vee catch)$If you are familiar with `pandas` you can use the dataframe below to find the solutions. You can of course also write code without using pandas or calculate the answers manually.  1. This asks for the probability that Toothache is true.$$P (toothache ) = 0.108 + 0.012 + 0.016 + 0.064 = 0.2$$1. This asks for the vector of probability values for the random variable Cavity. It has twovalues, which we list in the order htrue, falsei. First add up $0.108 + 0.012 + 0.072 +0.008 = 0.2$. Then we have$$P(Cavity) = \langle 0.2, 0.8\rangle.$$1. This asks for the vector of probability values for Toothache, given that Cavity is true.$$P(Toothache |cavity) = \langle(.108 + .012)/0.2, (0.072 + 0.008)/0.2\rangle = \langle 0.6, 0.4\rangle$$1. This asks for the vector of probability values for Cavity, given that either Toothache orCatch is true. First compute $P(toothache\vee catch) = 0.108 + 0.012 + 0.016 + 0.064 +0.072 + 0.144 = 0.416$. Then$$P(Cavity|toothache \vee catch) =\langle(0.108 + 0.012 + 0.072)/0.416, (0.016 + 0.064 + 0.144)/0.416\rangle =\langle 0.4615, 0.5384 \rangle$$<jupyter_code>import pandas as pd
columns = pd.MultiIndex.from_product((('toothache', '¬toothache'), ('catch', '¬catch'))) 
index = ('cavity', '¬cavity')
data = [[0.108, 0.012, 0.072, 0.008],
        [0.016, 0.064, 0.144, 0.576]]
joint_distribution = pd.DataFrame(data, index, columns)
joint_distribution
# 1.
joint_distribution.sum().sum(level=0)
# 2.
joint_distribution.sum(axis='columns')
# 3.
joint_distribution.loc['cavity', :].sum(level=0) / joint_distribution.loc['cavity', :].sum()
# 4. 
toothache_or_catch = joint_distribution.sum(axis='columns') - joint_distribution.loc[:, ('¬toothache', '¬catch')]
toothache_or_catch / toothache_or_catch.sum()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15303350437669785, 'fraction_numerical': 0.06912164201629943, 'mean_word_length': 2.9218934911242602, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '230877', 'license': 'MIT', 'n_tokens_mistral': 1157, 'n_tokens_neox': 977, 'n_words': 362, 'path': 'sheet_11/sheet_11_machine-learning_solution.ipynb', 'repo_name': 'ArielMant0/ml2018', 'size': '3325'}