In [1]:
%load_ext autoreload
%autoreload 2
import re
import aphrodite.results
import sklearn.metrics
import pandas as pd

import vislab
import vislab.results
import vislab.datasets

In [2]:
label_df = vislab.datasets.wikipaintings.get_artist_df()

In [3]:
c = vislab.util.get_mongodb_client()['predict']['wikipaintings_artist_oct25']
if c.find({'features': 'noise'}).count() > 0:
    c.remove({'features': 'noise'})
pd.DataFrame([x for x in c.find()])


Out[3]:
_id data features num_test num_train num_val quadratic results_name score_test score_val task
0 526f0d569622958641aaee56 wikipaintings_artist_ALL [decaf_fc6] 8278 24834 8278 False data_wikipaintings_artist_ALL_features_['decaf... 0.450287 0.845612 clf
1 526f1dea9622958641aaee57 wikipaintings_artist_ALL [mc_bit] 8278 24834 8278 False data_wikipaintings_artist_ALL_features_['mc_bi... 0.540631 0.904710 clf

In [4]:
results_df, preds_panel = aphrodite.results.load_pred_results(
    'wikipaintings_artist_oct25', '/Users/sergeyk/work/aphrodite/data/results2/',
    multiclass=True, force=True)
pred_prefix = 'pred'
print preds_panel.minor_axis


Results in collection wikipaintings_artist_oct25: 2
Index([u'decaf_fc6 False vw', u'mc_bit False vw'], dtype='object')

In [99]:
preds_panel.minor_xs('decaf_fc6 False vw')


Out[99]:
<class 'pandas.core.frame.DataFrame'>
Index: 34708 entries, albert-bierstadt_bison-with-coyotes-in-the-background to zinaida-serebriakova_young-moroccan-1932
Columns: 195 entries, artist_albert-bierstadt to split
dtypes: object(195)

In [5]:
mc_metrics = vislab.results.multiclass_metrics_feat_comparison(
    preds_panel, label_df, pred_prefix, features=preds_panel.minor_axis.tolist() + ['random'],
    balanced=True, with_plot=False, with_print=True)


Looks like the preds frame already has gt info.
Only taking 'test' split predictions.
********************decaf_fc6 False vw********************
Balancing dataset!
/Users/sergeyk/work/vislab/vislab/results.py:72: UserWarning: The precision and recall are equal to zero for some labels. fbeta_score is ill defined for those labels [ True]. 
  pred_df['label'], pred_df['pred_bin'])
/Users/sergeyk/work/vislab/vislab/results.py:72: UserWarning: The sum of true positives and false positives are equal to zero for some labels. Precision is ill defined for those labels [ True]. The precision and recall are equal to zero for some labels. fbeta_score is ill defined for those labels [ True]. 
  pred_df['label'], pred_df['pred_bin'])
/Users/sergeyk/work/vislab/vislab/results.py:284: UserWarning: The sum of true positives and false positives are equal to zero for some labels. Precision is ill defined for those labels [49]. The precision and recall are equal to zero for some labels. fbeta_score is ill defined for those labels [18 49]. 
  y_true, y_pred)
artist_albrecht-durer       112
artist_aleksey-savrasov      57
artist_alfred-sisley         93
artist_amedeo-modigliani     66
artist_aubrey-beardsley      54
artist_berthe-morisot        59
artist_boris-kustodiev      101
artist_camille-corot         89
artist_camille-pissarro     122
artist_childe-hassam         92
artist_claude-monet         178
artist_david-burliuk         62
artist_edgar-degas           95
artist_edouard-cortes        69
artist_edouard-manet         62
...
artist_theodor-severin-kittelsen      26
artist_thomas-eakins                  72
artist_tintoretto                     66
artist_titian                         67
artist_utagawa-kuniyoshi              64
artist_valentin-serov                 52
artist_vasily-polenov                 54
artist_vasily-surikov                 55
artist_vasily-vereshchagin            50
artist_vincent-van-gogh              204
artist_william-adolphe-bouguereau     58
artist_william-merritt-chase          66
artist_william-turner                 56
artist_zdislav-beksinski              82
artist_zinaida-serebriakova           54
Length: 91, dtype: int64
------------------------------------------------------------
Classification metrics on {} balanced
                                      precision    recall  f1-score  support
artist_albrecht-durer                  0.325000  0.565217  0.412698       23
artist_aleksey-savrasov                0.615385  0.695652  0.653061       23
artist_alfred-sisley                   0.461538  0.521739  0.489796       23
artist_amedeo-modigliani               0.750000  0.913043  0.823529       23
artist_aubrey-beardsley                0.888889  0.695652  0.780488       23
artist_berthe-morisot                  0.285714  0.260870  0.272727       23
artist_boris-kustodiev                 0.368421  0.304348  0.333333       23
artist_camille-corot                   0.400000  0.608696  0.482759       23
artist_camille-pissarro                0.333333  0.217391  0.263158       23
artist_childe-hassam                   0.280000  0.304348  0.291667       23
artist_claude-monet                    0.348837  0.652174  0.454545       23
artist_david-burliuk                   0.533333  0.347826  0.421053       23
artist_edgar-degas                     0.366667  0.478261  0.415094       23
artist_edouard-cortes                  0.913043  0.913043  0.913043       23
artist_edouard-manet                   0.041667  0.043478  0.042553       23
artist_egon-schiele                    0.647059  0.478261  0.550000       23
artist_ernst-ludwig-kirchner           0.629630  0.739130  0.680000       23
artist_eugene-boudin                   0.575758  0.826087  0.678571       23
artist_eugene-delacroix                0.000000  0.000000  0.000000       23
artist_eyvind-earle                    0.814815  0.956522  0.880000       23
artist_felix-vallotton                 0.272727  0.130435  0.176471       23
artist_ferdinand-hodler                0.136364  0.130435  0.133333       23
artist_fernand-leger                   0.952381  0.869565  0.909091       23
artist_francisco-goya                  0.578947  0.478261  0.523810       23
artist_gene-davis                      0.807692  0.913043  0.857143       23
artist_georges-braque                  0.666667  0.173913  0.275862       23
artist_giovanni-battista-piranesi      0.850000  0.739130  0.790698       23
artist_giovanni-boldini                0.380952  0.347826  0.363636       23
artist_gustave-courbet                 0.280000  0.304348  0.291667       23
artist_gustave-dore                    0.500000  0.826087  0.622951       23
artist_gustave-loiseau                 0.580645  0.782609  0.666667       23
artist_henri-de-toulouse-lautrec       0.285714  0.260870  0.272727       23
artist_henri-fantin-latour             0.484848  0.695652  0.571429       23
artist_henri-martin                    0.571429  0.181818  0.275862       22
artist_henri-matisse                   0.411765  0.304348  0.350000       23
artist_ilya-mashkov                    0.333333  0.086957  0.137931       23
artist_ilya-repin                      0.370370  0.434783  0.400000       23
artist_isaac-levitan                   0.241379  0.304348  0.269231       23
artist_ivan-aivazovsky                 0.655172  0.826087  0.730769       23
artist_ivan-bilibin                    0.384615  0.217391  0.277778       23
artist_ivan-shishkin                   0.395349  0.739130  0.515152       23
artist_jacek-yerka                     0.631579  0.521739  0.571429       23
artist_james-tissot                    0.458333  0.478261  0.468085       23
artist_jan-matejko                     0.578947  0.478261  0.523810       23
artist_jean-auguste-dominique-ingres   0.444444  0.347826  0.390244       23
artist_joaqu-n-sorolla                 0.285714  0.434783  0.344828       23
artist_john-henry-twachtman            0.409091  0.391304  0.400000       23
artist_john-singer-sargent             0.115385  0.130435  0.122449       23
artist_katsushika-hokusai              0.352941  0.260870  0.300000       23
artist_kazimir-malevich                0.000000  0.000000  0.000000       23
artist_konstantin-korovin              0.240000  0.260870  0.250000       23
artist_konstantin-makovsky             0.421053  0.347826  0.380952       23
artist_konstantin-somov                0.200000  0.173913  0.186047       23
artist_kuzma-petrov-vodkin             0.266667  0.347826  0.301887       23
artist_lucian-freud                    0.562500  0.391304  0.461538       23
artist_m-c-escher                      0.592593  0.695652  0.640000       23
artist_marc-chagall                    0.413793  0.521739  0.461538       23
artist_martiros-saryan                 0.421053  0.347826  0.380952       23
artist_mary-cassatt                    0.450000  0.391304  0.418605       23
artist_maurice-prendergast             0.535714  0.652174  0.588235       23
artist_max-ernst                       0.631579  0.521739  0.571429       23
artist_nicholas-roerich                0.444444  0.521739  0.480000       23
artist_odilon-redon                    0.500000  0.521739  0.510638       23
artist_orest-kiprensky                 0.476190  0.434783  0.454545       23
artist_pablo-picasso                   0.206897  0.260870  0.230769       23
artist_paul-cezanne                    0.382353  0.565217  0.456140       23
artist_paul-gauguin                    0.258065  0.347826  0.296296       23
artist_peter-paul-rubens               0.346154  0.391304  0.367347       23
artist_pierre-auguste-renoir           0.470588  0.695652  0.561404       23
artist_pierre-bonnard                  0.222222  0.086957  0.125000       23
artist_pyotr-konchalovsky              0.296296  0.347826  0.320000       23
artist_raphael-kirchner                0.600000  0.782609  0.679245       23
artist_rembrandt                       0.300000  0.521739  0.380952       23
artist_rene-magritte                   0.357143  0.434783  0.392157       23
artist_salvador-dali                   0.307692  0.173913  0.222222       23
artist_sam-francis                     0.800000  0.869565  0.833333       23
artist_theodor-severin-kittelsen       0.727273  0.347826  0.470588       23
artist_thomas-eakins                   0.210526  0.173913  0.190476       23
artist_tintoretto                      0.360000  0.391304  0.375000       23
artist_titian                          0.470588  0.347826  0.400000       23
artist_utagawa-kuniyoshi               0.620690  0.782609  0.692308       23
artist_valentin-serov                  0.157895  0.130435  0.142857       23
artist_vasily-polenov                  0.142857  0.086957  0.108108       23
artist_vasily-surikov                  0.214286  0.260870  0.235294       23
artist_vasily-vereshchagin             0.272727  0.130435  0.176471       23
artist_vincent-van-gogh                0.470588  0.347826  0.400000       23
artist_william-adolphe-bouguereau      0.565217  0.565217  0.565217       23
artist_william-merritt-chase           0.285714  0.260870  0.272727       23
artist_william-turner                  0.642857  0.391304  0.486486       23
artist_zdislav-beksinski               0.681818  0.652174  0.666667       23
artist_zinaida-serebriakova            0.535714  0.652174  0.588235       23
accuracy: 0.444550669216

Looks like the preds frame already has gt info.
Only taking 'test' split predictions.
********************mc_bit False vw********************
Balancing dataset!
artist_albrecht-durer       112
artist_aleksey-savrasov      57
artist_alfred-sisley         93
artist_amedeo-modigliani     66
artist_aubrey-beardsley      54
artist_berthe-morisot        59
artist_boris-kustodiev      101
artist_camille-corot         89
artist_camille-pissarro     122
artist_childe-hassam         92
artist_claude-monet         179
artist_david-burliuk         62
artist_edgar-degas           95
artist_edouard-cortes        69
artist_edouard-manet         63
...
artist_theodor-severin-kittelsen      26
artist_thomas-eakins                  72
artist_tintoretto                     65
artist_titian                         67
artist_utagawa-kuniyoshi              64
artist_valentin-serov                 52
artist_vasily-polenov                 54
artist_vasily-surikov                 55
artist_vasily-vereshchagin            50
artist_vincent-van-gogh              205
artist_william-adolphe-bouguereau     58
artist_william-merritt-chase          66
artist_william-turner                 56
artist_zdislav-beksinski              82
artist_zinaida-serebriakova           54
Length: 91, dtype: int64
------------------------------------------------------------
Classification metrics on {} balanced
                                      precision    recall  f1-score  support
artist_albrecht-durer                  0.447368  0.739130  0.557377       23
artist_aleksey-savrasov                0.750000  0.782609  0.765957       23
artist_alfred-sisley                   0.500000  0.478261  0.488889       23
artist_amedeo-modigliani               0.535714  0.652174  0.588235       23
artist_aubrey-beardsley                0.772727  0.739130  0.755556       23
artist_berthe-morisot                  0.777778  0.304348  0.437500       23
artist_boris-kustodiev                 0.173913  0.347826  0.231884       23
artist_camille-corot                   0.333333  0.521739  0.406780       23
artist_camille-pissarro                0.333333  0.478261  0.392857       23
artist_childe-hassam                   0.411765  0.608696  0.491228       23
artist_claude-monet                    0.348837  0.652174  0.454545       23
artist_david-burliuk                   0.650000  0.565217  0.604651       23
artist_edgar-degas                     0.515152  0.739130  0.607143       23
artist_edouard-cortes                  1.000000  0.913043  0.954545       23
artist_edouard-manet                   0.333333  0.130435  0.187500       23
artist_egon-schiele                    0.687500  0.478261  0.564103       23
artist_ernst-ludwig-kirchner           0.566667  0.739130  0.641509       23
artist_eugene-boudin                   0.720000  0.782609  0.750000       23
artist_eugene-delacroix                0.333333  0.086957  0.137931       23
artist_eyvind-earle                    0.833333  0.869565  0.851064       23
artist_felix-vallotton                 0.733333  0.478261  0.578947       23
artist_ferdinand-hodler                0.684211  0.565217  0.619048       23
artist_fernand-leger                   0.916667  0.956522  0.936170       23
artist_francisco-goya                  0.583333  0.608696  0.595745       23
artist_gene-davis                      0.947368  0.782609  0.857143       23
artist_georges-braque                  1.000000  0.347826  0.516129       23
artist_giovanni-battista-piranesi      0.821429  1.000000  0.901961       23
artist_giovanni-boldini                0.363636  0.173913  0.235294       23
artist_gustave-courbet                 0.388889  0.304348  0.341463       23
artist_gustave-dore                    0.718750  1.000000  0.836364       23
artist_gustave-loiseau                 0.809524  0.739130  0.772727       23
artist_henri-de-toulouse-lautrec       0.500000  0.521739  0.510638       23
artist_henri-fantin-latour             0.850000  0.739130  0.790698       23
artist_henri-martin                    1.000000  0.272727  0.428571       22
artist_henri-matisse                   0.583333  0.608696  0.595745       23
artist_ilya-mashkov                    0.727273  0.347826  0.470588       23
artist_ilya-repin                      0.285714  0.521739  0.369231       23
artist_isaac-levitan                   0.441176  0.652174  0.526316       23
artist_ivan-aivazovsky                 0.680000  0.739130  0.708333       23
artist_ivan-bilibin                    0.857143  0.521739  0.648649       23
artist_ivan-shishkin                   0.459459  0.739130  0.566667       23
artist_jacek-yerka                     0.909091  0.869565  0.888889       23
artist_james-tissot                    0.464286  0.565217  0.509804       23
artist_jan-matejko                     0.750000  0.521739  0.615385       23
artist_jean-auguste-dominique-ingres   0.700000  0.304348  0.424242       23
artist_joaqu-n-sorolla                 0.428571  0.391304  0.409091       23
artist_john-henry-twachtman            0.611111  0.478261  0.536585       23
artist_john-singer-sargent             0.333333  0.608696  0.430769       23
artist_katsushika-hokusai              0.923077  0.521739  0.666667       23
artist_kazimir-malevich                1.000000  0.217391  0.357143       23
artist_konstantin-korovin              0.625000  0.434783  0.512821       23
artist_konstantin-makovsky             0.555556  0.652174  0.600000       23
artist_konstantin-somov                0.444444  0.173913  0.250000       23
artist_kuzma-petrov-vodkin             0.833333  0.434783  0.571429       23
artist_lucian-freud                    0.777778  0.608696  0.682927       23
artist_m-c-escher                      0.823529  0.608696  0.700000       23
artist_marc-chagall                    0.473684  0.782609  0.590164       23
artist_martiros-saryan                 0.466667  0.304348  0.368421       23
artist_mary-cassatt                    0.555556  0.434783  0.487805       23
artist_maurice-prendergast             0.645161  0.869565  0.740741       23
artist_max-ernst                       0.823529  0.608696  0.700000       23
artist_nicholas-roerich                0.393939  0.565217  0.464286       23
artist_odilon-redon                    0.666667  0.782609  0.720000       23
artist_orest-kiprensky                 0.818182  0.391304  0.529412       23
artist_pablo-picasso                   0.244444  0.478261  0.323529       23
artist_paul-cezanne                    0.478261  0.478261  0.478261       23
artist_paul-gauguin                    0.379310  0.478261  0.423077       23
artist_peter-paul-rubens               0.500000  0.565217  0.530612       23
artist_pierre-auguste-renoir           0.476190  0.869565  0.615385       23
artist_pierre-bonnard                  0.600000  0.130435  0.214286       23
artist_pyotr-konchalovsky              0.516129  0.695652  0.592593       23
artist_raphael-kirchner                0.548387  0.739130  0.629630       23
artist_rembrandt                       0.485714  0.739130  0.586207       23
artist_rene-magritte                   0.400000  0.434783  0.416667       23
artist_salvador-dali                   0.388889  0.608696  0.474576       23
artist_sam-francis                     0.956522  0.956522  0.956522       23
artist_theodor-severin-kittelsen       1.000000  0.260870  0.413793       23
artist_thomas-eakins                   0.250000  0.173913  0.205128       23
artist_tintoretto                      0.562500  0.391304  0.461538       23
artist_titian                          0.428571  0.391304  0.409091       23
artist_utagawa-kuniyoshi               0.620690  0.782609  0.692308       23
artist_valentin-serov                  0.307692  0.173913  0.222222       23
artist_vasily-polenov                  0.461538  0.260870  0.333333       23
artist_vasily-surikov                  0.450000  0.391304  0.418605       23
artist_vasily-vereshchagin             0.600000  0.260870  0.363636       23
artist_vincent-van-gogh                0.418605  0.782609  0.545455       23
artist_william-adolphe-bouguereau      0.857143  0.782609  0.818182       23
artist_william-merritt-chase           0.500000  0.347826  0.410256       23
artist_william-turner                  0.750000  0.521739  0.615385       23
artist_zdislav-beksinski               0.580645  0.782609  0.666667       23
artist_zinaida-serebriakova            0.451613  0.608696  0.518519       23
accuracy: 0.554493307839

Looks like the preds frame already has gt info.
Only taking 'test' split predictions.
********************random********************
Balancing dataset!
/Users/sergeyk/work/vislab/vislab/results.py:72: UserWarning: The sum of true positives and false positives are equal to zero for some labels. Precision is ill defined for those labels [False]. The precision and recall are equal to zero for some labels. fbeta_score is ill defined for those labels [False]. 
  pred_df['label'], pred_df['pred_bin'])
/Users/sergeyk/work/vislab/vislab/results.py:284: UserWarning: The precision and recall are equal to zero for some labels. fbeta_score is ill defined for those labels [ 0  1  2  3  4  5  6  7  9 10 11 12 13 14 15 16 17 18 22 23 24 25 26 27 28
 29 31 32 33 34 35 36 37 38 39 41 42 43 45 46 47 48 49 50 51 52 54 55 56 57
 58 59 61 62 63 64 65 66 67 68 70 72 73 74 76 77 78 79 80 81 82 83 84 85 86
 87 89 90]. 
  y_true, y_pred)
artist_albrecht-durer       112
artist_aleksey-savrasov      57
artist_alfred-sisley         93
artist_amedeo-modigliani     66
artist_aubrey-beardsley      54
artist_berthe-morisot        59
artist_boris-kustodiev      101
artist_camille-corot         89
artist_camille-pissarro     122
artist_childe-hassam         92
artist_claude-monet         178
artist_david-burliuk         62
artist_edgar-degas           95
artist_edouard-cortes        69
artist_edouard-manet         62
...
artist_theodor-severin-kittelsen      26
artist_thomas-eakins                  72
artist_tintoretto                     66
artist_titian                         67
artist_utagawa-kuniyoshi              64
artist_valentin-serov                 52
artist_vasily-polenov                 54
artist_vasily-surikov                 55
artist_vasily-vereshchagin            50
artist_vincent-van-gogh              204
artist_william-adolphe-bouguereau     58
artist_william-merritt-chase          66
artist_william-turner                 56
artist_zdislav-beksinski              82
artist_zinaida-serebriakova           54
Length: 91, dtype: int64
------------------------------------------------------------
Classification metrics on {} balanced
                                      precision    recall  f1-score  support
artist_albrecht-durer                  0.000000  0.000000  0.000000       23
artist_aleksey-savrasov                0.000000  0.000000  0.000000       23
artist_alfred-sisley                   0.000000  0.000000  0.000000       23
artist_amedeo-modigliani               0.000000  0.000000  0.000000       23
artist_aubrey-beardsley                0.000000  0.000000  0.000000       23
artist_berthe-morisot                  0.000000  0.000000  0.000000       23
artist_boris-kustodiev                 0.000000  0.000000  0.000000       23
artist_camille-corot                   0.000000  0.000000  0.000000       23
artist_camille-pissarro                0.033333  0.043478  0.037736       23
artist_childe-hassam                   0.000000  0.000000  0.000000       23
artist_claude-monet                    0.000000  0.000000  0.000000       23
artist_david-burliuk                   0.000000  0.000000  0.000000       23
artist_edgar-degas                     0.000000  0.000000  0.000000       23
artist_edouard-cortes                  0.000000  0.000000  0.000000       23
artist_edouard-manet                   0.000000  0.000000  0.000000       23
artist_egon-schiele                    0.000000  0.000000  0.000000       23
artist_ernst-ludwig-kirchner           0.000000  0.000000  0.000000       23
artist_eugene-boudin                   0.000000  0.000000  0.000000       23
artist_eugene-delacroix                0.000000  0.000000  0.000000       23
artist_eyvind-earle                    0.040000  0.043478  0.041667       23
artist_felix-vallotton                 0.038462  0.043478  0.040816       23
artist_ferdinand-hodler                0.090909  0.043478  0.058824       23
artist_fernand-leger                   0.000000  0.000000  0.000000       23
artist_francisco-goya                  0.000000  0.000000  0.000000       23
artist_gene-davis                      0.000000  0.000000  0.000000       23
artist_georges-braque                  0.000000  0.000000  0.000000       23
artist_giovanni-battista-piranesi      0.000000  0.000000  0.000000       23
artist_giovanni-boldini                0.000000  0.000000  0.000000       23
artist_gustave-courbet                 0.000000  0.000000  0.000000       23
artist_gustave-dore                    0.000000  0.000000  0.000000       23
artist_gustave-loiseau                 0.052632  0.043478  0.047619       23
artist_henri-de-toulouse-lautrec       0.000000  0.000000  0.000000       23
artist_henri-fantin-latour             0.000000  0.000000  0.000000       23
artist_henri-martin                    0.000000  0.000000  0.000000       22
artist_henri-matisse                   0.000000  0.000000  0.000000       23
artist_ilya-mashkov                    0.000000  0.000000  0.000000       23
artist_ilya-repin                      0.000000  0.000000  0.000000       23
artist_isaac-levitan                   0.000000  0.000000  0.000000       23
artist_ivan-aivazovsky                 0.000000  0.000000  0.000000       23
artist_ivan-bilibin                    0.000000  0.000000  0.000000       23
artist_ivan-shishkin                   0.043478  0.043478  0.043478       23
artist_jacek-yerka                     0.000000  0.000000  0.000000       23
artist_james-tissot                    0.000000  0.000000  0.000000       23
artist_jan-matejko                     0.000000  0.000000  0.000000       23
artist_jean-auguste-dominique-ingres   0.071429  0.043478  0.054054       23
artist_joaqu-n-sorolla                 0.000000  0.000000  0.000000       23
artist_john-henry-twachtman            0.000000  0.000000  0.000000       23
artist_john-singer-sargent             0.000000  0.000000  0.000000       23
artist_katsushika-hokusai              0.000000  0.000000  0.000000       23
artist_kazimir-malevich                0.000000  0.000000  0.000000       23
artist_konstantin-korovin              0.000000  0.000000  0.000000       23
artist_konstantin-makovsky             0.000000  0.000000  0.000000       23
artist_konstantin-somov                0.000000  0.000000  0.000000       23
artist_kuzma-petrov-vodkin             0.076923  0.086957  0.081633       23
artist_lucian-freud                    0.000000  0.000000  0.000000       23
artist_m-c-escher                      0.000000  0.000000  0.000000       23
artist_marc-chagall                    0.000000  0.000000  0.000000       23
artist_martiros-saryan                 0.000000  0.000000  0.000000       23
artist_mary-cassatt                    0.000000  0.000000  0.000000       23
artist_maurice-prendergast             0.000000  0.000000  0.000000       23
artist_max-ernst                       0.045455  0.043478  0.044444       23
artist_nicholas-roerich                0.000000  0.000000  0.000000       23
artist_odilon-redon                    0.000000  0.000000  0.000000       23
artist_orest-kiprensky                 0.000000  0.000000  0.000000       23
artist_pablo-picasso                   0.000000  0.000000  0.000000       23
artist_paul-cezanne                    0.000000  0.000000  0.000000       23
artist_paul-gauguin                    0.000000  0.000000  0.000000       23
artist_peter-paul-rubens               0.000000  0.000000  0.000000       23
artist_pierre-auguste-renoir           0.000000  0.000000  0.000000       23
artist_pierre-bonnard                  0.047619  0.043478  0.045455       23
artist_pyotr-konchalovsky              0.000000  0.000000  0.000000       23
artist_raphael-kirchner                0.043478  0.043478  0.043478       23
artist_rembrandt                       0.000000  0.000000  0.000000       23
artist_rene-magritte                   0.000000  0.000000  0.000000       23
artist_salvador-dali                   0.000000  0.000000  0.000000       23
artist_sam-francis                     0.043478  0.043478  0.043478       23
artist_theodor-severin-kittelsen       0.000000  0.000000  0.000000       23
artist_thomas-eakins                   0.000000  0.000000  0.000000       23
artist_tintoretto                      0.000000  0.000000  0.000000       23
artist_titian                          0.000000  0.000000  0.000000       23
artist_utagawa-kuniyoshi               0.000000  0.000000  0.000000       23
artist_valentin-serov                  0.000000  0.000000  0.000000       23
artist_vasily-polenov                  0.000000  0.000000  0.000000       23
artist_vasily-surikov                  0.000000  0.000000  0.000000       23
artist_vasily-vereshchagin             0.000000  0.000000  0.000000       23
artist_vincent-van-gogh                0.000000  0.000000  0.000000       23
artist_william-adolphe-bouguereau      0.000000  0.000000  0.000000       23
artist_william-merritt-chase           0.000000  0.000000  0.000000       23
artist_william-turner                  0.058824  0.043478  0.050000       23
artist_zdislav-beksinski               0.000000  0.000000  0.000000       23
artist_zinaida-serebriakova            0.000000  0.000000  0.000000       23
accuracy: 0.00669216061185


In [6]:
# Force-directed graph of confusion matrix
conf_df = mc_metrics['feat_metrics']['mc_bit False vw']['conf_df']
conf_df_n = conf_df.astype(float) / conf_df.sum(1)

In [7]:
fig = vislab.dataset_viz.plot_occurrence(conf_df_n)



In [8]:
for row_ix, row in conf_df_n.iloc[:5].iterrows():
    print [(row_ix, col_ix, val) for col_ix, val in row.iteritems() if val > 0]


[('artist_albrecht-durer', 'artist_albrecht-durer', 0.73913043478260865), ('artist_albrecht-durer', 'artist_boris-kustodiev', 0.043478260869565216), ('artist_albrecht-durer', 'artist_ivan-bilibin', 0.043478260869565216), ('artist_albrecht-durer', 'artist_pablo-picasso', 0.086956521739130432), ('artist_albrecht-durer', 'artist_vasily-surikov', 0.043478260869565216), ('artist_albrecht-durer', 'artist_william-merritt-chase', 0.043478260869565216)]
[('artist_aleksey-savrasov', 'artist_aleksey-savrasov', 0.78260869565217395), ('artist_aleksey-savrasov', 'artist_isaac-levitan', 0.043478260869565216), ('artist_aleksey-savrasov', 'artist_ivan-aivazovsky', 0.086956521739130432), ('artist_aleksey-savrasov', 'artist_ivan-shishkin', 0.086956521739130432)]
[('artist_alfred-sisley', 'artist_alfred-sisley', 0.47826086956521741), ('artist_alfred-sisley', 'artist_camille-corot', 0.043478260869565216), ('artist_alfred-sisley', 'artist_camille-pissarro', 0.17391304347826086), ('artist_alfred-sisley', 'artist_childe-hassam', 0.043478260869565216), ('artist_alfred-sisley', 'artist_claude-monet', 0.043478260869565216), ('artist_alfred-sisley', 'artist_david-burliuk', 0.043478260869565216), ('artist_alfred-sisley', 'artist_gustave-loiseau', 0.043478260869565216), ('artist_alfred-sisley', 'artist_isaac-levitan', 0.043478260869565216), ('artist_alfred-sisley', 'artist_pyotr-konchalovsky', 0.086956521739130432)]
[('artist_amedeo-modigliani', 'artist_amedeo-modigliani', 0.65217391304347827), ('artist_amedeo-modigliani', 'artist_edgar-degas', 0.086956521739130432), ('artist_amedeo-modigliani', 'artist_felix-vallotton', 0.043478260869565216), ('artist_amedeo-modigliani', 'artist_kuzma-petrov-vodkin', 0.043478260869565216), ('artist_amedeo-modigliani', 'artist_nicholas-roerich', 0.043478260869565216), ('artist_amedeo-modigliani', 'artist_paul-gauguin', 0.043478260869565216), ('artist_amedeo-modigliani', 'artist_sam-francis', 0.043478260869565216), ('artist_amedeo-modigliani', 'artist_valentin-serov', 0.043478260869565216)]
[('artist_aubrey-beardsley', 'artist_albrecht-durer', 0.043478260869565216), ('artist_aubrey-beardsley', 'artist_aubrey-beardsley', 0.73913043478260865), ('artist_aubrey-beardsley', 'artist_boris-kustodiev', 0.043478260869565216), ('artist_aubrey-beardsley', 'artist_francisco-goya', 0.043478260869565216), ('artist_aubrey-beardsley', 'artist_m-c-escher', 0.043478260869565216), ('artist_aubrey-beardsley', 'artist_rembrandt', 0.043478260869565216), ('artist_aubrey-beardsley', 'artist_vincent-van-gogh', 0.043478260869565216)]

In [9]:
import networkx as nx
g = nx.DiGraph()
for row_ix, row in conf_df_n.iterrows():
    g.add_weighted_edges_from([(row_ix, col_ix, val) for col_ix, val in row.iteritems() if val > 0])
graph = g

In [10]:
import sklearn.cluster
artists = graph.nodes()
M = nx.adjacency_matrix(graph, artists)
M[np.diag_indices(M.shape[0])] = 0
cl = sklearn.cluster.SpectralClustering(n_clusters=4)
labels = cl.fit_predict(M)
df = pd.DataFrame({'artist': artists, 'label': labels}).sort('label')
#print df.to_string()


/Users/sergeyk/anaconda/python.app/Contents/lib/python2.7/site-packages/sklearn/cluster/spectral.py:442: UserWarning: The spectral clustering API has changed. ``fit``now constructs an affinity matrix from data. To use a custom affinity matrix, set ``affinity=precomputed``.
  warnings.warn("The spectral clustering API has changed. ``fit``"
/Users/sergeyk/anaconda/python.app/Contents/lib/python2.7/site-packages/numpy/lib/utils.py:139: DeprecationWarning: `scipy.lib.lapack` is deprecated, use `scipy.linalg.lapack` instead!
  warnings.warn(depdoc, DeprecationWarning)

In [13]:
pos_spring = nx.spring_layout(graph, iterations=50)
#pos_dot = nx.graphviz_layout(graph, prog='dot')

fig = plt.figure(figsize=(20,20))
ax = fig.add_subplot(111)
nx.draw(
    graph, pos_spring,
    node_color='#A0CBE2', edge_color='#BB0000',
    width=.1, edge_cmap=plt.cm.Blues, with_labels=True,
    ax=ax)



In [14]:
pos_neato = nx.graphviz_layout(graph, prog='dot')
#pos_sfdp = nx.graphviz_layout(graph, prog='sfdp')
pos = pos_neato

gray = (0.75,0.75,0.75,1)
graydark = (0.5,0.5,0.5,1)
cmap = pyplot.get_cmap('Paired')

# nodes
nx.draw_networkx_nodes(graph, pos, \
        with_labels = False, node_size=40, \
        node_color=gray, linewidth=None).set_edgecolor(graydark)
# edges
nx.draw_networkx_edges(graph, pos, \
        arrows=False, edge_color=[gray]*len(graph.edges()))


Out[14]:
<matplotlib.collections.LineCollection at 0x119b6d990>