
sawine@0: \documentclass[a4paper, 10pt, pagesize, smallheadings]{article}
sawine@0: \usepackage{graphicx}
sawine@0: %\usepackage[latin1]{inputenc}
sawine@0: \usepackage{amsmath, amsthm, amssymb}
sawine@0: \usepackage{typearea}
sawine@0: \usepackage{algorithm}
sawine@0: \usepackage{algorithmic}
sawine@0: \usepackage{fullpage}
sawine@0: \usepackage{mathtools}
sawine@0: \usepackage[all]{xy}
sawine@0: \usepackage{tikz}
sawine@0: \usepackage{tikz-qtree}
sawine@0: \addtolength{\voffset}{-40pt}
sawine@0: \title{Machine Learning Exercise 01 Solution}
sawine@0: \author{Eugen Sawin}
sawine@0: \renewcommand{\familydefault}{\sfdefault}
sawine@0: \newcommand{\E}{\mathcal{E}}
sawine@0: \newcommand{\R}{\mathcal{R}}
sawine@0: 
sawine@0: %\include{pythonlisting}
sawine@0: 
sawine@0: \pagestyle{empty}
sawine@0: \begin{document}
sawine@0: \maketitle
sawine@0: 
sawine@0: \section*{Exercise 1.1}
sawine@0: (a) Possible Pacman tasks that could be solved using machine learning are:
sawine@0: \begin{itemize}
sawine@0:   \item Survival: learn to escape the ghosts.
sawine@0:   \item Fight back: learn to eat ghosts when they are vulnerable.
sawine@0:   \item Eat: maximise dots eaten per elapsed time.
sawine@0: \end{itemize}
sawine@0: (b) I would apply supervised learning on:
sawine@0: \begin{itemize}
sawine@0:   \item Predict tomorrow’s price of a particular stock
sawine@0:   \item Predict your life expectancy
sawine@0:   \item Predict if it is going to rain tomorrow
sawine@0: \end{itemize}
sawine@0: (c) The following problems are classification problems:
sawine@0: \begin{itemize}
sawine@0:   \item Predict if it is going to rain tomorrow
sawine@0: \end{itemize}
sawine@0: 
sawine@0: \section*{Exercise 1.2}
sawine@0: (a) A version space consists of all consistent hypothesis from a hypothesis space with respect to the given set of examples. The order is induced by the strict ordering \emph{more-general-than}($>_g$)/\emph{more-specific-than}($<_g$).
sawine@0: 
sawine@0: $S$ represents the set of the most specific consistent hypothesis (summary of all positive examples) and $G$ represents the set of the most general consistent hypothesis (summary of all negative examples). All other consistent hypothesis are between these given boundaries, implicitely. 
sawine@0: 
sawine@0: For inconsistent examples $S$ and $G$ become empty and so does the version space, this is also the case if the language used for the definition of the hypothesis space is insufficient to describe the target concept.\\\\
sawine@0: (b) Just imagine a beautiful looking graph here depicting the ordered hypothesis space.\\\\
sawine@0: (c)
sawine@0: \begin{tabular}{r c c}
sawine@0: $i$ & $S_i$ & $G_i$\\\hline
sawine@0: $0$ & $\{\langle \emptyset,\emptyset,\emptyset \rangle\}$
sawine@0:     & $\{\langle ?,?,? \rangle\}$\\
sawine@0: $1$ & $\{\langle +,+,+ \rangle\}$
sawine@0:     & $\{\langle ?,?,? \rangle\}$\\
sawine@0: $2$ & $\{\langle +,+,? \rangle\}$
sawine@0:     & $\{\langle ?,?,? \rangle\}$\\
sawine@0: $3$ & $\{\langle +,+,? \rangle\}$
sawine@0:     & $\{\langle ?,+,? \rangle\}$\\
sawine@0: $4$ & $\{\langle +,+,? \rangle\}$
sawine@0:     & $\{\langle +,+,? \rangle\}$\\\hline
sawine@0: $5$ & $\{\langle +,+,? \rangle\}$
sawine@0:     & $\{\langle +,+,? \rangle\}$\\
sawine@0: $6$ & $\{\langle +,+,? \rangle\}$
sawine@0:     & $\{\langle +,+,? \rangle\}$\\
sawine@0: \end{tabular}\\\\
sawine@0: (d) No, but it does affect the convergence speed. The hypothesis space represents a systematic model of all consistent hypothesis and does not converge to local specialisations.\\\\
sawine@0: (e) For concrete target concept like $\langle +,+ \rangle$ three examples are enough, one positive and two negative. For a concrete general concept like $\langle +,? \rangle$ we need four examples, two of each type. For the trivial concept $\langle ?,? \rangle$ two (obviously) positive examples are enough.\\\\
sawine@0: (f)
sawine@0: \begin{tabular}{r c c}
sawine@0: $i$ & $S_i$ & $G_i$\\\hline
sawine@0: $0$ & $\{\langle \emptyset,\emptyset,\emptyset.\emptyset \rangle\}$
sawine@0:     & $\{\langle ?,?,?,? \rangle\}$\\
sawine@0: $1$ & $\{\langle +,+,+,- \rangle\}$
sawine@0:     & $\{\langle ?,?,?,? \rangle\}$\\
sawine@0: $2$ & $\{\langle +,+,?,- \rangle\}$
sawine@0:     & $\{\langle ?,?,?,? \rangle\}$\\
sawine@0: $3$ & $\{\langle ?,?,?,? \rangle\}$
sawine@0:     & $\{\langle ?,?,?,? \rangle\}$\\
sawine@0: \end{tabular}\\
sawine@0: It converged to a wrong hypothesis. If we move example $d_3$, it will result in an empty set $S$ and therefore not consistent hypothesis, because the concept to be learned is not in the defined hypothesis space.
sawine@0: 
sawine@0: \section*{Exercise 1.3}
sawine@0: (a) $E(S) = -\frac{1}{7}\log_2\frac{1}{7}-\frac{2}{7}\log_2\frac{2}{7}-\frac{2}{7}\log_2\frac{2}{7}-\frac{2}{7}\log_2\frac{2}{7} \approx 1.95$\\
sawine@0: $E(S|fever) = \frac{2}{7}(1) + \frac{3}{7}(2) + \frac{2}{7}(1) \approx 1.64$\\
sawine@0: $E(S|vomiting) = \frac{4}{7}(-2\frac{1}{4}\log_2\frac{1}{4}-\frac{2}{4}\log_2\frac{2}{4}) + \frac{3}{7}(-\frac{1}{3}\log_2\frac{1}{3}-\frac{2}{3}\log_2\frac{2}{3}) \approx 1.25$\\
sawine@0: $E(S|diarrhea) = \frac{3}{7}(-\frac{2}{3}\log_2\frac{2}{3}-\frac{1}{3}\log_2\frac{1}{3}) + \frac{4}{7}(-\log_2\frac{2}{4}) \approx 0.96$\\
sawine@0: $E(S|shivering) = \frac{6}{7}(-2\frac{1}{6}\log_2\frac{1}{6}-2\frac{2}{6}\log_2\frac{2}{6}) + \frac{1}{7}\cdot 0 \approx 1.64$\\
sawine@0: As we can clearly see, we get the greates gain with diarrhea $G(S,diarrhea) = 1.95 - 0.96 = 0.99$. Since the human brain is quite good at approximating entropy, this was visible from the beginning and I will refrain from calculating it for each step. So here is the tree.
sawine@0: \begin{figure}[h]
sawine@0: \centering
sawine@0: \begin{tikzpicture}[level distance=50pt, sibling distance=30pt]
sawine@0: \Tree
sawine@0:   [.\node[draw]{diarrhea}; 
sawine@0:       \edge node[auto=right]{no}; [.\node[draw]{fever}; 
sawine@0:         \edge node[auto=right]{no}; \node[draw]{H};  
sawine@0:         \edge node[auto=right]{avg}; \node[draw]{I};
sawine@0:         \edge node[auto=left]{high}; \node[draw]{I};
sawine@0:       ]
sawine@0:       \edge node[auto=left]{yes}; [.\node[draw]{fever};
sawine@0:         \edge node[auto=right]{no}; \node[draw]{B};
sawine@0:         \edge node[auto=left]{avg}; [.\node[draw]{vomiting};
sawine@0:           \edge node[auto=right]{no}; \node[draw]{S};
sawine@0:           \edge node[auto=left]{yes}; \node[draw]{B};
sawine@0:         ]
sawine@0:         \edge node[auto=left]{high}; \node[draw]{S};
sawine@0:       ]
sawine@0:   ]
sawine@0: \end{tikzpicture}
sawine@0: \caption{The complete search tree with the dotted edges depicting the solution path.}
sawine@0: \label{searchtree}
sawine@0: \end{figure}\\
sawine@0: (b) I'm just assuming what a disjoint definition is, no it does not, since both average and high fever results in influenza in the case of diarrhea.\\\\
sawine@0: (c) Candidates are $A = \frac{164+169}{2}$, $B=\frac{175+176}{2}$, $C=\frac{179+180}{2}$, $D=\frac{184+185}{2}$.\\
sawine@0: $E(A) = \frac{2}{9}\cdot 0 + \frac{7}{9}(-\frac{4}{7}\log_2\frac{4}{7}-\frac{3}{7}\log_2\frac{3}{7}) \approx 0.77$\\
sawine@0: $E(B) = \frac{4}{9}\cdot 1 + \frac{5}{9}(-\frac{2}{5}\log_2\frac{2}{5}-\frac{3}{5}\log_2\frac{3}{5}) \approx 0.98$\\
sawine@0: $E(C) = \frac{6}{9}(-\frac{2}{6}\log_2\frac{2}{6}-\frac{4}{6}\log_2\frac{4}{6}) + \frac{3}{9}(-\frac{2}{3}\log_2\frac{2}{3}-\frac{1}{3}\log_2\frac{1}{3}) \approx 0.92$\\
sawine@0: $E(D) = \frac{8}{9}\cdot 1 + \frac{1}{9} \cdot 0 = 1$\\
sawine@0: Splitting threshold $A$ gives the lowest entropy and therefore greatest gain $G = 0.99 - 0.77 = 0.22$.
sawine@0: \end{document}




