Roberto Santana and Unai Garciarena
Department of Computer Science and Artificial Intelligence
University of the Basque Country
Computing the prediction with LDA: \[ p(y=1|x) = sigm \left( {\bf{w}}^T ({\bf{x}} - {\bf{x}}_0) \right) \]
Assuming that the a-priori probability of the two classes is the same: \[ \begin{align} w &= \Sigma^{-1} (\mu_1 - \mu_0) \\ {\bf{x}}_0 &= \frac{1}{2} (\mu_1 + \mu_0) \end{align} \]
Let the Bernoulli distribution be defined as: \[ Ber({\bf{x}},p) = p^{{\bf{x}}} (1-p)^{1-{\bf{x}}} \; \forall {\bf{x}} \in \{0,1\} \]
and the sigmoid function defined as: \[ g(\eta) = \frac{1}{1+e^{-\eta}} = \frac{e^{\eta}}{e^{\eta}+1} \]
Then the logistic regression classifier is defined as: \[ p(y \mid {\bf{x}}, {\bf{w}}) = Ber(y, g({\bf{w}}^T {\bf{x}})) \]
K. P. Murphy. Machine learning. A probabilistic perspective. MIT Press. 2012.
S. Russell and P. Norvig. Artificial Intelligence. A Modern Approach. Third Edition. Pearson Press. 2010.
S. Russell and P. Norvig. Artificial Intelligence. A Modern Approach. Third Edition. Pearson Press. 2010.
Criteria/Flat | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | C1 | C2 | C3 |
---|---|---|---|---|---|---|---|---|---|---|---|
Price | high | low | med. | high | low | med. | med. | high | med. | high | low |
Distance to University | far | far | close | close | close | close | close | close | far | far | close |
Parking | no | no | no | no | no | yes | no | no | no | no | yes |
Cool Roommates? | cool | cool | cool | no | no | cool | cool | cool | cool | cool | no |
Flat owner | nice | nice | not nice | nice | not nice | not nice | not nice | ? | nice | ? | ? |
Heating for winter | no | no | no | yes | yes | no | yes | yes | no | no | yes |
Distance to Bus | close | close | close | far | close | close | far | far | far | close | close |
Room space | med. | large | small | small | small | med. | small | small | med. | small | small |
Noisy area | no | yes | yes | no | no | yes | yes | no | no | no | no |
Mother advice | yes | ? | no | ? | no | yes | yes | no | yes | no | no |
Cat | no | yes | no | no | yes | yes | no | yes | yes | no | no |
Kitchen | small | small | large | med. | med. | small | small | med. | large | small | small |
Distance to beach | far | far | close | close | far | far | far | far | far | far | far |
Floor | 2 | 7 | 1 | 1 | 0 | 3 | 1 | 2 | 4 | 0 | 3 |
Elevator | no | yes | no | no | no | no | no | no | no | yes | yes |
Bars around | yes | yes | yes | yes | no | yes | no | no | no | yes | no |
Did (Will) I like it? | no | yes | no | no | no | yes | yes | no | ? | ? | ? |
Criteria/Flat | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | C1 | C2 | C3 |
---|---|---|---|---|---|---|---|---|---|---|---|
Price | high | low | med. | high | low | med. | med. | high | med. | high | low |
Distance to University | far | far | close | close | close | close | close | close | far | far | close |
Cool Roommates? | cool | cool | cool | no | no | cool | cool | cool | cool | cool | no |
Mother advice | yes | ? | no | ? | no | yes | yes | no | yes | no | no |
Cat | no | yes | no | no | yes | yes | no | yes | yes | no | no |
Did (Will) I like it? | no | yes | no | no | no | yes | yes | no | ? | ? | ? |
S. Russell and P. Norvig. Artificial Intelligence. A Modern Approach. Third Edition. Pearson Press. 2010.
Criteria/Flat | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 |
---|---|---|---|---|---|---|---|---|
Price | high | low | med. | high | low | med. | med. | high |
Distance to University | far | far | close | close | close | close | close | close |
Cool Roommates? | cool | cool | cool | no | no | cool | cool | cool |
Mother advice | yes | ? | no | ? | no | yes | yes | no |
Cat | no | yes | no | no | yes | yes | no | yes |
Did (Will) I like it? | no | yes | no | no | no | yes | yes | no |
Criteria/Value | p(class=yes) | p(class=no) | Impurity | Entropy | Error | <
---|---|---|---|---|---|
Price/high | p(class=yes)=0 | p(class=no)=1 | 0 | 0 | 0 | <
Price/low | p(class=yes)=0.5 | p(class=no)=0.5 | 0.5 | \(-2*0.5^2*log(0.5) \) | 0.5 | <
cat/yes | p(class=yes)=0.5 | p(class=no)=0.5 | 0.5 | \(-2*0.5^2*log(0.5) \) | 0.5 | <
cat/no | p(class=yes)=0.25 | p(class=no)=0.75 | ? | ? | ? | <
S. Russell and P. Norvig. Artificial Intelligence. A Modern Approach. Third Edition. Pearson Press. 2010.
L. Breimann. Bagging predictors. Machine Learning. Vol. 24 No. 2. Pp. 123--140. 1996.
Figure credit. Sebastian Raschka. How does the random forest model work?
L. Breimann. Random Forests. Machine Learning. Vol. 45 No. 1. Pp. 5--32. 2001.
L. Breimann. Random Forests. Machine Learning. Vol. 45 No. 1. Pp. 5--32. 2001.
Figure credit. Sklearn. Feature importances with forests of trees.
ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | -1 | 1 |
2 | 1 | 0 | 0 | 0 | -1 | 1 |
3 | 0 | 0 | 1 | 1 | 1 | -1 |
4 | 1 | 1 | 0 | 0 | -1 | -1 |
5 | 1 | 1 | 1 | 0 | 1 | 1 |
6 | 0 | 1 | 0 | 1 | -1 | 1 |
7 | 0 | 0 | 0 | 0 | 1 | 1 |
8 | 1 | 1 | 1 | 1 | 1 | -1 |
ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | -1 | 1 |
2 | 1 | 0 | 0 | 0 | -1 | 1 |
3 | 0 | 0 | 1 | 1 | 1 | -1 |
4 | 1 | 1 | 0 | 0 | -1 | -1 |
5 | 1 | 1 | 1 | 0 | 1 | 1 |
6 | 0 | 1 | 0 | 1 | -1 | 1 |
7 | 0 | 0 | 0 | 0 | 1 | 1 |
8 | 1 | 1 | 1 | 1 | 1 | -1 |
ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | -1 | 1 |
2 | 1 | 0 | 0 | 0 | -1 | 1 |
3 | 0 | 0 | 1 | 1 | 1 | -1 |
4 | 1 | 1 | 0 | 0 | -1 | -1 |
5 | 1 | 1 | 1 | 0 | 1 | 1 |
6 | 0 | 1 | 0 | 1 | -1 | 1 |
7 | 0 | 0 | 0 | 0 | 1 | 1 |
8 | 1 | 1 | 1 | 1 | 1 | -1 |
\[ Accuracy = \frac{TP+TN}{P+N} \]
\[ Sensitivity = \frac{TP}{P} \]
\[ Specificity = \frac{TN}{N} \]
\[ Precision = \frac{TP}{TP+FP} \]
\[ Recall = \frac{TP}{TP+FN} \]
\[ BACC = \frac{\frac{TP}{P} + \frac{TN}{N}}{2} \]
\[ F1 = \frac{2TP}{2TP+FP+FN} \]
ind. | X0 | X1 | X2 | X3 | X4 | Class | Prediction |
---|---|---|---|---|---|---|---|
1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |
2 | 0 | 1 | 0 | 0 | 0 | 1 | 1 |
3 | 1 | 0 | 0 | 1 | 1 | 1 | 1 |
4 | 1 | 1 | 0 | 0 | 0 | 1 | 1 |
5 | 1 | 1 | 1 | 0 | 1 | 1 | 1 |
6 | 0 | 0 | 1 | 0 | 1 | -1 | 1 |
7 | 1 | 1 | 0 | 0 | 0 | -1 | 1 |
8 | 0 | 1 | 1 | 0 | 1 | -1 | 1 |
9 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
10 | 1 | 0 | 1 | 0 | 1 | 1 | 1 |
11 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |
12 | 0 | 1 | 1 | 1 | 1 | 1 | -1 |
True Class | |||
---|---|---|---|
Good | Bad | ||
Predicted | Good | 3 | 2 |
Bad | 1 | 2 |
True Class | ||||
---|---|---|---|---|
Small | Medium | Large | ||
Predicted Class | Small | 100 | 30 | 15 |
Medium | 0 | 40 | 5 | |
Large | 0 | 30 | 80 |
True Class | |||
---|---|---|---|
Positive | Negative | ||
Predicted Class | Positive | TP | FP |
Negative | FN | TN |
Fold | ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|---|
1 | 1 | 0 | 0 | 1 | 0 | -1 | |
1 | 2 | 1 | 0 | 0 | 0 | -1 | |
2 | 3 | 0 | 0 | 1 | 1 | 1 | |
2 | 4 | 1 | 1 | 0 | 0 | -1 | |
3 | 5 | 1 | 1 | 1 | 0 | 1 | |
3 | 6 | 0 | 1 | 0 | 1 | -1 | |
4 | 7 | 0 | 0 | 0 | 0 | 1 | |
4 | 8 | 1 | 1 | 1 | 1 | 1 | |
5 | 9 | 0 | 0 | 0 | 0 | 1 | |
5 | 10 | 1 | 1 | 1 | 1 | 1 |
ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | -1 | |
2 | 1 | 0 | 0 | 0 | -1 | |
3 | 0 | 0 | 1 | 1 | 1 | |
4 | 1 | 1 | 0 | 0 | -1 | |
5 | 1 | 1 | 1 | 0 | 1 | |
6 | 0 | 1 | 0 | 1 | -1 | |
7 | 0 | 0 | 0 | 0 | 1 | |
8 | 1 | 1 | 1 | 1 | 1 | |
9 | 0 | 0 | 0 | 0 | 1 | |
10 | 1 | 1 | 1 | 1 | 1 |
ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | -1 | |
2 | 1 | 0 | 0 | 0 | -1 | |
3 | 0 | 0 | 1 | 1 | 1 | |
4 | 1 | 1 | 0 | 0 | -1 | |
5 | 1 | 1 | 1 | 0 | 1 | |
6 | 0 | 1 | 0 | 1 | -1 | |
7 | 0 | 0 | 0 | 0 | 1 | |
8 | 1 | 1 | 1 | 1 | 1 | |
9 | 0 | 0 | 0 | 0 | 1 | |
10 | 1 | 1 | 1 | 1 | 1 |
ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | -1 | |
2 | 1 | 0 | 0 | 0 | -1 | |
3 | 0 | 0 | 1 | 1 | 1 | |
4 | 1 | 1 | 0 | 0 | -1 | |
5 | 1 | 1 | 1 | 0 | 1 | |
6 | 0 | 1 | 0 | 1 | -1 | |
7 | 0 | 0 | 0 | 0 | 1 | |
8 | 1 | 1 | 1 | 1 | 1 | |
9 | 0 | 0 | 0 | 0 | 1 | -1 |
10 | 1 | 1 | 1 | 1 | 1 | 1 |
ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | -1 | |
2 | 1 | 0 | 0 | 0 | -1 | |
3 | 0 | 0 | 1 | 1 | 1 | |
4 | 1 | 1 | 0 | 0 | -1 | |
5 | 1 | 1 | 1 | 0 | 1 | |
6 | 0 | 1 | 0 | 1 | -1 | |
7 | 0 | 0 | 0 | 0 | 1 | |
8 | 1 | 1 | 1 | 1 | 1 | |
9 | 0 | 0 | 0 | 0 | 1 | -1 |
10 | 1 | 1 | 1 | 1 | 1 | 1 |
ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | -1 | |
2 | 1 | 0 | 0 | 0 | -1 | |
3 | 0 | 0 | 1 | 1 | 1 | |
4 | 1 | 1 | 0 | 0 | -1 | |
5 | 1 | 1 | 1 | 0 | 1 | |
6 | 0 | 1 | 0 | 1 | -1 | |
7 | 0 | 0 | 0 | 0 | 1 | 1 |
8 | 1 | 1 | 1 | 1 | 1 | -1 |
9 | 0 | 0 | 0 | 0 | 1 | -1 |
10 | 1 | 1 | 1 | 1 | 1 | 1 |
ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | -1 | |
2 | 1 | 0 | 0 | 0 | -1 | |
3 | 0 | 0 | 1 | 1 | 1 | |
4 | 1 | 1 | 0 | 0 | -1 | |
5 | 1 | 1 | 1 | 0 | 1 | 1 |
6 | 0 | 1 | 0 | 1 | -1 | -1 |
7 | 0 | 0 | 0 | 0 | 1 | 1 |
8 | 1 | 1 | 1 | 1 | 1 | -1 |
9 | 0 | 0 | 0 | 0 | 1 | -1 |
10 | 1 | 1 | 1 | 1 | 1 | 1 |
ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | -1 | |
2 | 1 | 0 | 0 | 0 | -1 | |
3 | 0 | 0 | 1 | 1 | 1 | -1 |
4 | 1 | 1 | 0 | 0 | -1 | -1 |
5 | 1 | 1 | 1 | 0 | 1 | 1 |
6 | 0 | 1 | 0 | 1 | -1 | -1 |
7 | 0 | 0 | 0 | 0 | 1 | 1 |
8 | 1 | 1 | 1 | 1 | 1 | -1 |
9 | 0 | 0 | 0 | 0 | 1 | -1 |
10 | 1 | 1 | 1 | 1 | 1 | 1 |
ind. | X0 | X1 | X2 | X3 | Class | Prediction |
---|---|---|---|---|---|---|
1 | 0 | 0 | 1 | 0 | -1 | 1 |
2 | 1 | 0 | 0 | 0 | -1 | 1 |
3 | 0 | 0 | 1 | 1 | 1 | -1 |
4 | 1 | 1 | 0 | 0 | -1 | -1 |
5 | 1 | 1 | 1 | 0 | 1 | 1 |
6 | 0 | 1 | 0 | 1 | -1 | -1 |
7 | 0 | 0 | 0 | 0 | 1 | 1 |
8 | 1 | 1 | 1 | 1 | 1 | -1 |
9 | 0 | 0 | 0 | 0 | 1 | -1 |
10 | 1 | 1 | 1 | 1 | 1 | 1 |