# Canonical Clustering

## $k$ Nearest-Neighbor
### Distance Measure
The $k$ nearest neighbor is based on the simple idea that when a sample is close to other samples, changes are that they share the same label. To know how close one sample is from another sample, there needs to be a notion of close. For this application we will use euclidian distance also known as the $L^2$ norm

$$ \left\| x \right\|_2 \overset{\textrm{def}}= \left( \sum_{i=1}^n x_i^2 \right)^{1/2}$$

### Classification
In classification we would like to assign certain samples to a class. To do so we would like to implement an algorithm that assigns the class based on the classes of the $k$ nearest neighbors. Try to do so in `.code/knn.py`


```python
import sys
sys.path.append('code/')
import knn

import numpy as np

from sklearn import datasets, model_selection
from sklearn.metrics import adjusted_rand_score

# import some data to play with
X, y = datasets.load_iris(return_X_y=True)

# inspect the shape of the data
print(X.shape)
print(y.shape)

# split data into train and test
X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y)

# and predict
k=10
y_predicted = knn.predict(X_train, X_test, y_train, k)

# evaluate predictions using y_predicted and y_test
ARI = adjusted_rand_score(np.squeeze(y_predicted), np.squeeze(y_test))
print("Adjusted Rand Index is: {0}".format(ARI))
```

    (150, 4)
    (150,)
    Adjusted Rand Index is: 0.8640044217217079


## Naive Bayes
#### TODO: probably this exercise is to extensive, rewrite it with using libraries.
### Dataset
Naive Bayes classifier is often used to filter emails for spam, such as in [this article](https://www.aclweb.org/anthology/E03-1059.pdf). For this exercise we will use a dataset containing samples from email messages. This dataset is available on [openml](https://www.openml.org/d/42673) and can be read in using sklearn:


```python
from sklearn import datasets
import numpy as np
spam = datasets.fetch_openml('auml_eml_1_a')

# lets inspect the dataset
np.set_printoptions(precision=3, suppress=True)
print("Dataset Dictionary Keys: \n{0}\n".format(spam.keys()))
print("Dataset Feature Names: \n{0}\n".format(spam['feature_names']))

# print a few examples of spam and non-spam
print("Example spam data entries: \n{0}\n".format(spam['data'][spam['target']==0][:8,:].T))
print("Example spam targets: \n{0}\n".format(spam['target'][spam['target']==0][:8].T))
print("Example non-spam data entries: \n{0}\n".format(spam['data'][spam['target']==1][:8,:].T))
print("Example non-spam targets: \n{0}\n".format(spam['target'][spam['target']==1][:8].T))
```

    Dataset Dictionary Keys: 
    dict_keys(['data', 'target', 'frame', 'categories', 'feature_names', 'target_names', 'DESCR', 'details', 'url'])
    
    Dataset Feature Names: 
    ['F1_text_html_found', 'F1_number_of_links', 'F1_contains_javascript']
    
    Example spam data entries: 
    [[0. 0. 0. 0. 0. 0. 0. 0.]
     [0. 0. 5. 4. 3. 3. 0. 0.]
     [0. 0. 0. 0. 0. 0. 0. 0.]]
    
    Example spam targets: 
    [0. 0. 0. 0. 0. 0. 0. 0.]
    
    Example non-spam data entries: 
    [[0. 0. 0. 0. 0. 0. 0. 0.]
     [0. 0. 0. 0. 0. 0. 0. 0.]
     [0. 0. 0. 0. 0. 0. 0. 0.]]
    
    Example non-spam targets: 
    [1. 1. 1. 1. 1. 1. 1. 1.]
    


This dataset contains 3 features. The first is a binary feature named 'F1_text_html_found', the second is a nominal feature named 'F1_number_of_links', and the last is again a binary feature named 'F1_contains_javascript'. Using these three features, we are going to try to predict the change of a sample being spam. To do so we use:

\begin{align}
P(Y=y_k | X=x_i) = \frac{P(Y=y_k) P(X=x_i | Y=y_k)}{P(X=x_i)}
\end{align}

This is an alternative way of writing:

\begin{align}
P(Y=y_k | X=x_i) = \frac{P(Y=y_k) P(X_1=x_{i,1} \wedge \ldots \wedge X_d=x_{i,d}) | Y=y_k)}{P(X_1=x_{i,1} \wedge \ldots \wedge X_d=x_{i,d})}
\end{align}

The nominator is often omitted, because it scales all classes the same so when comparing classes it does not matter to omit it. Furthermore, it simplifies the calculation. Thus we ultimately we will use:

\begin{align}
P(Y=y_k | X=x_i) = P(Y=y_k) P(X_1=x_{i,1} \wedge \ldots \wedge X_d=x_{i,d}) | Y=y_k)
\end{align}

To use this formula, we first need to define what the probality distribution is. For a binary this is relatively simple. For the counted feature 'F1_number_of_links', we will use a probability distribution based on a histogram with bins with a width of $10$. Implement these probabilities in `code/utils.py`.


```python
import sys
sys.path.append('code/')
import naive_bayes

import pprint
from sklearn.model_selection import train_test_split

X = spam.data
y = spam.target

X_train, X_test, y_train, y_test = train_test_split(X,y, stratify=y)

feature_types = ['binary', 'histogram', 'binary']

model = naive_bayes.fit(X_train, y_train, feature_types)

# inspect model
#pprint.pprint(model)

y_predict = naive_bayes.predict(X_test, model)
```

    {'0': 0.8903432228039558,
     '0_featureset': {'0': {'0': 0.9895459000326691, '1': 0.010454099967330937},
                      '1': {'1': 0.5050637046716759,
                            '10': 0.005227049983665469,
                            '100': 0.0,
                            '101': 0.0,
                            '102': 0.0,
                            '103': 0.0,
                            '104': 0.0,
                            '105': 0.0,
                            '106': 0.0,
                            '107': 0.0003266906239790918,
                            '108': 0.0003266906239790918,
                            '109': 0.0,
                            '11': 0.00914733747141457,
                            '110': 0.0,
                            '111': 0.0,
                            '112': 0.0,
                            '113': 0.0,
                            '114': 0.0,
                            '115': 0.0,
                            '116': 0.0,
                            '117': 0.0,
                            '118': 0.0,
                            '119': 0.0,
                            '12': 0.003266906239790918,
                            '120': 0.0,
                            '121': 0.0,
                            '122': 0.0,
                            '123': 0.0,
                            '124': 0.0,
                            '125': 0.0003266906239790918,
                            '126': 0.0,
                            '127': 0.0,
                            '128': 0.0,
                            '129': 0.0,
                            '13': 0.005880431231623653,
                            '130': 0.0,
                            '131': 0.0,
                            '132': 0.0003266906239790918,
                            '133': 0.0,
                            '134': 0.0003266906239790918,
                            '135': 0.0,
                            '136': 0.0003266906239790918,
                            '137': 0.0,
                            '138': 0.0003266906239790918,
                            '139': 0.0003266906239790918,
                            '14': 0.0022868343678536427,
                            '140': 0.0,
                            '141': 0.0003266906239790918,
                            '142': 0.0,
                            '143': 0.0,
                            '144': 0.0003266906239790918,
                            '145': 0.0,
                            '146': 0.0,
                            '147': 0.0,
                            '148': 0.0,
                            '149': 0.0,
                            '15': 0.004900359359686377,
                            '150': 0.0,
                            '151': 0.0,
                            '152': 0.0,
                            '153': 0.0,
                            '154': 0.0,
                            '155': 0.0,
                            '156': 0.0,
                            '157': 0.0,
                            '158': 0.0,
                            '159': 0.0,
                            '16': 0.0029402156158118264,
                            '160': 0.0,
                            '161': 0.0,
                            '162': 0.0,
                            '163': 0.0,
                            '164': 0.0,
                            '165': 0.0,
                            '166': 0.0,
                            '167': 0.0,
                            '168': 0.0,
                            '169': 0.0,
                            '17': 0.0019601437438745506,
                            '170': 0.0,
                            '171': 0.0,
                            '172': 0.0,
                            '173': 0.0,
                            '174': 0.0,
                            '175': 0.0,
                            '176': 0.0,
                            '177': 0.0,
                            '178': 0.0,
                            '179': 0.0,
                            '18': 0.0035935968637700096,
                            '180': 0.0,
                            '181': 0.0,
                            '182': 0.0,
                            '183': 0.0,
                            '184': 0.0,
                            '185': 0.0,
                            '186': 0.0,
                            '187': 0.0,
                            '188': 0.0,
                            '189': 0.0,
                            '19': 0.0013067624959163672,
                            '190': 0.0,
                            '191': 0.0,
                            '192': 0.0,
                            '193': 0.0,
                            '194': 0.0,
                            '195': 0.0,
                            '196': 0.0,
                            '197': 0.0,
                            '198': 0.0,
                            '199': 0.0,
                            '2': 0.12381574648807579,
                            '20': 0.0013067624959163672,
                            '200': 0.0,
                            '201': 0.0,
                            '202': 0.0,
                            '203': 0.0,
                            '204': 0.0,
                            '205': 0.0,
                            '206': 0.0,
                            '207': 0.0,
                            '208': 0.0,
                            '209': 0.0,
                            '21': 0.0029402156158118264,
                            '210': 0.0,
                            '211': 0.0,
                            '212': 0.0,
                            '22': 0.003266906239790918,
                            '23': 0.001633453119895459,
                            '24': 0.0013067624959163672,
                            '25': 0.0013067624959163672,
                            '26': 0.001633453119895459,
                            '27': 0.0009800718719372753,
                            '28': 0.0009800718719372753,
                            '29': 0.0,
                            '3': 0.06599150604377654,
                            '30': 0.0,
                            '31': 0.0006533812479581836,
                            '32': 0.0003266906239790918,
                            '33': 0.0006533812479581836,
                            '34': 0.0006533812479581836,
                            '35': 0.0003266906239790918,
                            '36': 0.0009800718719372753,
                            '37': 0.0009800718719372753,
                            '38': 0.0006533812479581836,
                            '39': 0.0006533812479581836,
                            '4': 0.04083632799738648,
                            '40': 0.0006533812479581836,
                            '41': 0.0003266906239790918,
                            '42': 0.0003266906239790918,
                            '43': 0.0006533812479581836,
                            '44': 0.0003266906239790918,
                            '45': 0.0003266906239790918,
                            '46': 0.0,
                            '47': 0.0009800718719372753,
                            '48': 0.0003266906239790918,
                            '49': 0.0013067624959163672,
                            '5': 0.045083306109114665,
                            '50': 0.0003266906239790918,
                            '51': 0.0,
                            '52': 0.0003266906239790918,
                            '53': 0.0,
                            '54': 0.0006533812479581836,
                            '55': 0.0003266906239790918,
                            '56': 0.0,
                            '57': 0.0,
                            '58': 0.0,
                            '59': 0.0,
                            '6': 0.10192747468147664,
                            '60': 0.0,
                            '61': 0.0006533812479581836,
                            '62': 0.0,
                            '63': 0.0003266906239790918,
                            '64': 0.0003266906239790918,
                            '65': 0.0003266906239790918,
                            '66': 0.0,
                            '67': 0.0,
                            '68': 0.0,
                            '69': 0.0003266906239790918,
                            '7': 0.013067624959163672,
                            '70': 0.0003266906239790918,
                            '71': 0.0,
                            '72': 0.0003266906239790918,
                            '73': 0.0,
                            '74': 0.0,
                            '75': 0.0003266906239790918,
                            '76': 0.0,
                            '77': 0.0,
                            '78': 0.0,
                            '79': 0.0003266906239790918,
                            '8': 0.01110748121528912,
                            '80': 0.0,
                            '81': 0.0,
                            '82': 0.0,
                            '83': 0.0003266906239790918,
                            '84': 0.0,
                            '85': 0.0,
                            '86': 0.0,
                            '87': 0.0,
                            '88': 0.0,
                            '89': 0.0003266906239790918,
                            '9': 0.016007840574975497,
                            '90': 0.0,
                            '91': 0.0006533812479581836,
                            '92': 0.0,
                            '93': 0.0,
                            '94': 0.0,
                            '95': 0.0,
                            '96': 0.0,
                            '97': 0.0003266906239790918,
                            '98': 0.0,
                            '99': 0.0},
                      '2': {'0': 0.999673309376021, '1': 0.0003266906239790918}},
     '1': 0.1096567771960442,
     '1_featureset': {'0': {'0': 0.4907161803713528, '1': 0.5092838196286472},
                      '1': {'1': 0.41909814323607425,
                            '10': 0.002652519893899204,
                            '100': 0.0,
                            '101': 0.0,
                            '102': 0.0,
                            '103': 0.0,
                            '104': 0.0,
                            '105': 0.0,
                            '106': 0.0,
                            '107': 0.0,
                            '108': 0.0,
                            '109': 0.0,
                            '11': 0.0,
                            '110': 0.0,
                            '111': 0.0,
                            '112': 0.0,
                            '113': 0.0,
                            '114': 0.0,
                            '115': 0.0,
                            '116': 0.0,
                            '117': 0.0,
                            '118': 0.0,
                            '119': 0.0,
                            '12': 0.0,
                            '120': 0.0,
                            '121': 0.0,
                            '122': 0.0,
                            '123': 0.0,
                            '124': 0.0,
                            '125': 0.0,
                            '126': 0.0,
                            '127': 0.0,
                            '128': 0.0,
                            '129': 0.0,
                            '13': 0.0,
                            '130': 0.0,
                            '131': 0.0,
                            '132': 0.0,
                            '133': 0.0,
                            '134': 0.0,
                            '135': 0.0,
                            '136': 0.0,
                            '137': 0.0,
                            '138': 0.0,
                            '139': 0.0,
                            '14': 0.0,
                            '140': 0.0,
                            '141': 0.0,
                            '142': 0.0,
                            '143': 0.0,
                            '144': 0.0,
                            '145': 0.0,
                            '146': 0.0,
                            '147': 0.0,
                            '148': 0.0,
                            '149': 0.0,
                            '15': 0.0,
                            '150': 0.0,
                            '151': 0.0,
                            '152': 0.0,
                            '153': 0.0,
                            '154': 0.0,
                            '155': 0.0,
                            '156': 0.0,
                            '157': 0.0,
                            '158': 0.0,
                            '159': 0.0,
                            '16': 0.002652519893899204,
                            '160': 0.0,
                            '161': 0.0,
                            '162': 0.0,
                            '163': 0.0,
                            '164': 0.0,
                            '165': 0.0,
                            '166': 0.0,
                            '167': 0.0,
                            '168': 0.0,
                            '169': 0.0,
                            '17': 0.0,
                            '170': 0.0,
                            '171': 0.0,
                            '172': 0.0,
                            '173': 0.0,
                            '174': 0.0,
                            '175': 0.0,
                            '176': 0.0,
                            '177': 0.0,
                            '178': 0.0,
                            '179': 0.0,
                            '18': 0.0,
                            '180': 0.0,
                            '181': 0.0,
                            '182': 0.0,
                            '183': 0.0,
                            '184': 0.0,
                            '185': 0.0,
                            '186': 0.0,
                            '187': 0.0,
                            '188': 0.0,
                            '189': 0.0,
                            '19': 0.0,
                            '190': 0.0,
                            '191': 0.0,
                            '192': 0.0,
                            '193': 0.0,
                            '194': 0.0,
                            '195': 0.0,
                            '196': 0.0,
                            '197': 0.0,
                            '198': 0.0,
                            '199': 0.0,
                            '2': 0.4005305039787798,
                            '20': 0.0,
                            '200': 0.0,
                            '201': 0.0,
                            '202': 0.0,
                            '203': 0.0,
                            '204': 0.0,
                            '205': 0.0,
                            '206': 0.0,
                            '207': 0.0,
                            '208': 0.0,
                            '209': 0.0,
                            '21': 0.0,
                            '210': 0.0,
                            '211': 0.0,
                            '212': 0.0,
                            '22': 0.0,
                            '23': 0.0,
                            '24': 0.0,
                            '25': 0.0,
                            '26': 0.0,
                            '27': 0.0,
                            '28': 0.0,
                            '29': 0.0,
                            '3': 0.0636604774535809,
                            '30': 0.002652519893899204,
                            '31': 0.0,
                            '32': 0.002652519893899204,
                            '33': 0.0,
                            '34': 0.0,
                            '35': 0.0,
                            '36': 0.0,
                            '37': 0.0,
                            '38': 0.0,
                            '39': 0.0,
                            '4': 0.021220159151193633,
                            '40': 0.0,
                            '41': 0.0,
                            '42': 0.0,
                            '43': 0.0,
                            '44': 0.0,
                            '45': 0.0,
                            '46': 0.0,
                            '47': 0.0,
                            '48': 0.0,
                            '49': 0.0,
                            '5': 0.04509283819628647,
                            '50': 0.0,
                            '51': 0.0,
                            '52': 0.0,
                            '53': 0.002652519893899204,
                            '54': 0.0,
                            '55': 0.0,
                            '56': 0.0,
                            '57': 0.0,
                            '58': 0.0,
                            '59': 0.0,
                            '6': 0.023872679045092837,
                            '60': 0.002652519893899204,
                            '61': 0.0,
                            '62': 0.0,
                            '63': 0.0,
                            '64': 0.0,
                            '65': 0.0,
                            '66': 0.0,
                            '67': 0.0,
                            '68': 0.0,
                            '69': 0.002652519893899204,
                            '7': 0.002652519893899204,
                            '70': 0.0,
                            '71': 0.0,
                            '72': 0.0,
                            '73': 0.0,
                            '74': 0.0,
                            '75': 0.0,
                            '76': 0.0,
                            '77': 0.0,
                            '78': 0.0,
                            '79': 0.0,
                            '8': 0.002652519893899204,
                            '80': 0.0,
                            '81': 0.0,
                            '82': 0.0,
                            '83': 0.0,
                            '84': 0.0,
                            '85': 0.0,
                            '86': 0.0,
                            '87': 0.0,
                            '88': 0.0,
                            '89': 0.0,
                            '9': 0.002652519893899204,
                            '90': 0.0,
                            '91': 0.0,
                            '92': 0.0,
                            '93': 0.0,
                            '94': 0.0,
                            '95': 0.0,
                            '96': 0.0,
                            '97': 0.0,
                            '98': 0.0,
                            '99': 0.0},
                      '2': {'0': 0.9946949602122016, '1': 0.005305039787798408}}}
    Class number: 0
    Key: 0
    {'0': 0.9895459000326691, '1': 0.010454099967330937}
    Key: 1
    {'1': 0.5050637046716759,
     '10': 0.005227049983665469,
     '100': 0.0,
     '101': 0.0,
     '102': 0.0,
     '103': 0.0,
     '104': 0.0,
     '105': 0.0,
     '106': 0.0,
     '107': 0.0003266906239790918,
     '108': 0.0003266906239790918,
     '109': 0.0,
     '11': 0.00914733747141457,
     '110': 0.0,
     '111': 0.0,
     '112': 0.0,
     '113': 0.0,
     '114': 0.0,
     '115': 0.0,
     '116': 0.0,
     '117': 0.0,
     '118': 0.0,
     '119': 0.0,
     '12': 0.003266906239790918,
     '120': 0.0,
     '121': 0.0,
     '122': 0.0,
     '123': 0.0,
     '124': 0.0,
     '125': 0.0003266906239790918,
     '126': 0.0,
     '127': 0.0,
     '128': 0.0,
     '129': 0.0,
     '13': 0.005880431231623653,
     '130': 0.0,
     '131': 0.0,
     '132': 0.0003266906239790918,
     '133': 0.0,
     '134': 0.0003266906239790918,
     '135': 0.0,
     '136': 0.0003266906239790918,
     '137': 0.0,
     '138': 0.0003266906239790918,
     '139': 0.0003266906239790918,
     '14': 0.0022868343678536427,
     '140': 0.0,
     '141': 0.0003266906239790918,
     '142': 0.0,
     '143': 0.0,
     '144': 0.0003266906239790918,
     '145': 0.0,
     '146': 0.0,
     '147': 0.0,
     '148': 0.0,
     '149': 0.0,
     '15': 0.004900359359686377,
     '150': 0.0,
     '151': 0.0,
     '152': 0.0,
     '153': 0.0,
     '154': 0.0,
     '155': 0.0,
     '156': 0.0,
     '157': 0.0,
     '158': 0.0,
     '159': 0.0,
     '16': 0.0029402156158118264,
     '160': 0.0,
     '161': 0.0,
     '162': 0.0,
     '163': 0.0,
     '164': 0.0,
     '165': 0.0,
     '166': 0.0,
     '167': 0.0,
     '168': 0.0,
     '169': 0.0,
     '17': 0.0019601437438745506,
     '170': 0.0,
     '171': 0.0,
     '172': 0.0,
     '173': 0.0,
     '174': 0.0,
     '175': 0.0,
     '176': 0.0,
     '177': 0.0,
     '178': 0.0,
     '179': 0.0,
     '18': 0.0035935968637700096,
     '180': 0.0,
     '181': 0.0,
     '182': 0.0,
     '183': 0.0,
     '184': 0.0,
     '185': 0.0,
     '186': 0.0,
     '187': 0.0,
     '188': 0.0,
     '189': 0.0,
     '19': 0.0013067624959163672,
     '190': 0.0,
     '191': 0.0,
     '192': 0.0,
     '193': 0.0,
     '194': 0.0,
     '195': 0.0,
     '196': 0.0,
     '197': 0.0,
     '198': 0.0,
     '199': 0.0,
     '2': 0.12381574648807579,
     '20': 0.0013067624959163672,
     '200': 0.0,
     '201': 0.0,
     '202': 0.0,
     '203': 0.0,
     '204': 0.0,
     '205': 0.0,
     '206': 0.0,
     '207': 0.0,
     '208': 0.0,
     '209': 0.0,
     '21': 0.0029402156158118264,
     '210': 0.0,
     '211': 0.0,
     '212': 0.0,
     '22': 0.003266906239790918,
     '23': 0.001633453119895459,
     '24': 0.0013067624959163672,
     '25': 0.0013067624959163672,
     '26': 0.001633453119895459,
     '27': 0.0009800718719372753,
     '28': 0.0009800718719372753,
     '29': 0.0,
     '3': 0.06599150604377654,
     '30': 0.0,
     '31': 0.0006533812479581836,
     '32': 0.0003266906239790918,
     '33': 0.0006533812479581836,
     '34': 0.0006533812479581836,
     '35': 0.0003266906239790918,
     '36': 0.0009800718719372753,
     '37': 0.0009800718719372753,
     '38': 0.0006533812479581836,
     '39': 0.0006533812479581836,
     '4': 0.04083632799738648,
     '40': 0.0006533812479581836,
     '41': 0.0003266906239790918,
     '42': 0.0003266906239790918,
     '43': 0.0006533812479581836,
     '44': 0.0003266906239790918,
     '45': 0.0003266906239790918,
     '46': 0.0,
     '47': 0.0009800718719372753,
     '48': 0.0003266906239790918,
     '49': 0.0013067624959163672,
     '5': 0.045083306109114665,
     '50': 0.0003266906239790918,
     '51': 0.0,
     '52': 0.0003266906239790918,
     '53': 0.0,
     '54': 0.0006533812479581836,
     '55': 0.0003266906239790918,
     '56': 0.0,
     '57': 0.0,
     '58': 0.0,
     '59': 0.0,
     '6': 0.10192747468147664,
     '60': 0.0,
     '61': 0.0006533812479581836,
     '62': 0.0,
     '63': 0.0003266906239790918,
     '64': 0.0003266906239790918,
     '65': 0.0003266906239790918,
     '66': 0.0,
     '67': 0.0,
     '68': 0.0,
     '69': 0.0003266906239790918,
     '7': 0.013067624959163672,
     '70': 0.0003266906239790918,
     '71': 0.0,
     '72': 0.0003266906239790918,
     '73': 0.0,
     '74': 0.0,
     '75': 0.0003266906239790918,
     '76': 0.0,
     '77': 0.0,
     '78': 0.0,
     '79': 0.0003266906239790918,
     '8': 0.01110748121528912,
     '80': 0.0,
     '81': 0.0,
     '82': 0.0,
     '83': 0.0003266906239790918,
     '84': 0.0,
     '85': 0.0,
     '86': 0.0,
     '87': 0.0,
     '88': 0.0,
     '89': 0.0003266906239790918,
     '9': 0.016007840574975497,
     '90': 0.0,
     '91': 0.0006533812479581836,
     '92': 0.0,
     '93': 0.0,
     '94': 0.0,
     '95': 0.0,
     '96': 0.0,
     '97': 0.0003266906239790918,
     '98': 0.0,
     '99': 0.0}
    Key: 2
    {'0': 0.999673309376021, '1': 0.0003266906239790918}
    Class number: 1
    Key: 0
    {'0': 0.4907161803713528, '1': 0.5092838196286472}
    Key: 1
    {'1': 0.41909814323607425,
     '10': 0.002652519893899204,
     '100': 0.0,
     '101': 0.0,
     '102': 0.0,
     '103': 0.0,
     '104': 0.0,
     '105': 0.0,
     '106': 0.0,
     '107': 0.0,
     '108': 0.0,
     '109': 0.0,
     '11': 0.0,
     '110': 0.0,
     '111': 0.0,
     '112': 0.0,
     '113': 0.0,
     '114': 0.0,
     '115': 0.0,
     '116': 0.0,
     '117': 0.0,
     '118': 0.0,
     '119': 0.0,
     '12': 0.0,
     '120': 0.0,
     '121': 0.0,
     '122': 0.0,
     '123': 0.0,
     '124': 0.0,
     '125': 0.0,
     '126': 0.0,
     '127': 0.0,
     '128': 0.0,
     '129': 0.0,
     '13': 0.0,
     '130': 0.0,
     '131': 0.0,
     '132': 0.0,
     '133': 0.0,
     '134': 0.0,
     '135': 0.0,
     '136': 0.0,
     '137': 0.0,
     '138': 0.0,
     '139': 0.0,
     '14': 0.0,
     '140': 0.0,
     '141': 0.0,
     '142': 0.0,
     '143': 0.0,
     '144': 0.0,
     '145': 0.0,
     '146': 0.0,
     '147': 0.0,
     '148': 0.0,
     '149': 0.0,
     '15': 0.0,
     '150': 0.0,
     '151': 0.0,
     '152': 0.0,
     '153': 0.0,
     '154': 0.0,
     '155': 0.0,
     '156': 0.0,
     '157': 0.0,
     '158': 0.0,
     '159': 0.0,
     '16': 0.002652519893899204,
     '160': 0.0,
     '161': 0.0,
     '162': 0.0,
     '163': 0.0,
     '164': 0.0,
     '165': 0.0,
     '166': 0.0,
     '167': 0.0,
     '168': 0.0,
     '169': 0.0,
     '17': 0.0,
     '170': 0.0,
     '171': 0.0,
     '172': 0.0,
     '173': 0.0,
     '174': 0.0,
     '175': 0.0,
     '176': 0.0,
     '177': 0.0,
     '178': 0.0,
     '179': 0.0,
     '18': 0.0,
     '180': 0.0,
     '181': 0.0,
     '182': 0.0,
     '183': 0.0,
     '184': 0.0,
     '185': 0.0,
     '186': 0.0,
     '187': 0.0,
     '188': 0.0,
     '189': 0.0,
     '19': 0.0,
     '190': 0.0,
     '191': 0.0,
     '192': 0.0,
     '193': 0.0,
     '194': 0.0,
     '195': 0.0,
     '196': 0.0,
     '197': 0.0,
     '198': 0.0,
     '199': 0.0,
     '2': 0.4005305039787798,
     '20': 0.0,
     '200': 0.0,
     '201': 0.0,
     '202': 0.0,
     '203': 0.0,
     '204': 0.0,
     '205': 0.0,
     '206': 0.0,
     '207': 0.0,
     '208': 0.0,
     '209': 0.0,
     '21': 0.0,
     '210': 0.0,
     '211': 0.0,
     '212': 0.0,
     '22': 0.0,
     '23': 0.0,
     '24': 0.0,
     '25': 0.0,
     '26': 0.0,
     '27': 0.0,
     '28': 0.0,
     '29': 0.0,
     '3': 0.0636604774535809,
     '30': 0.002652519893899204,
     '31': 0.0,
     '32': 0.002652519893899204,
     '33': 0.0,
     '34': 0.0,
     '35': 0.0,
     '36': 0.0,
     '37': 0.0,
     '38': 0.0,
     '39': 0.0,
     '4': 0.021220159151193633,
     '40': 0.0,
     '41': 0.0,
     '42': 0.0,
     '43': 0.0,
     '44': 0.0,
     '45': 0.0,
     '46': 0.0,
     '47': 0.0,
     '48': 0.0,
     '49': 0.0,
     '5': 0.04509283819628647,
     '50': 0.0,
     '51': 0.0,
     '52': 0.0,
     '53': 0.002652519893899204,
     '54': 0.0,
     '55': 0.0,
     '56': 0.0,
     '57': 0.0,
     '58': 0.0,
     '59': 0.0,
     '6': 0.023872679045092837,
     '60': 0.002652519893899204,
     '61': 0.0,
     '62': 0.0,
     '63': 0.0,
     '64': 0.0,
     '65': 0.0,
     '66': 0.0,
     '67': 0.0,
     '68': 0.0,
     '69': 0.002652519893899204,
     '7': 0.002652519893899204,
     '70': 0.0,
     '71': 0.0,
     '72': 0.0,
     '73': 0.0,
     '74': 0.0,
     '75': 0.0,
     '76': 0.0,
     '77': 0.0,
     '78': 0.0,
     '79': 0.0,
     '8': 0.002652519893899204,
     '80': 0.0,
     '81': 0.0,
     '82': 0.0,
     '83': 0.0,
     '84': 0.0,
     '85': 0.0,
     '86': 0.0,
     '87': 0.0,
     '88': 0.0,
     '89': 0.0,
     '9': 0.002652519893899204,
     '90': 0.0,
     '91': 0.0,
     '92': 0.0,
     '93': 0.0,
     '94': 0.0,
     '95': 0.0,
     '96': 0.0,
     '97': 0.0,
     '98': 0.0,
     '99': 0.0}
    Key: 2
    {'0': 0.9946949602122016, '1': 0.005305039787798408}
    array([[5.289, 4.508],
           [4.368, 3.588],
           [4.329, 3.548],
           ...,
           [5.289, 4.508],
           [5.289, 4.508],
           [5.289, 4.508]])



```python
print(y_predict)
```

    [0 0 0 ... 0 0 0]



```python

```




    1147




```python

```

81180b44fba19e026d696f2024265cb4cd39f9d3
ipynb
Jupyter Notebook
solutions/canonical_classification/canonical_classification.ipynb
dloeffen/datamining-practicals
526d1feda7098766babcda77d1e14a0797f5316e
MIT
solutions/canonical_classification/canonical_classification.ipynb
dloeffen/datamining-practicals
526d1feda7098766babcda77d1e14a0797f5316e
MIT
2020-09-21T12:34:04.000Z
2020-09-23T10:10:19.000Z
solutions/canonical_classification/canonical_classification.ipynb
dloeffen/datamining-practicals
526d1feda7098766babcda77d1e14a0797f5316e
MIT
Qwen/Qwen-72B
1. YES
2. YES