Mercurial > hg > plosone_underreview
comparison notebooks/explain_components.ipynb @ 53:7532363b9dda branch-tests
added yticks and savefig in explain components
author | Maria Panteli <m.x.panteli@gmail.com> |
---|---|
date | Mon, 18 Sep 2017 11:25:05 +0100 |
parents | c4428589b82b |
children | 98cd5317e504 |
comparison
equal
deleted
inserted
replaced
52:635028c5be34 | 53:7532363b9dda |
---|---|
1 { | 1 { |
2 "cells": [ | 2 "cells": [ |
3 { | 3 { |
4 "cell_type": "code", | 4 "cell_type": "code", |
5 "execution_count": 1, | 5 "execution_count": 2, |
6 "metadata": { | 6 "metadata": { |
7 "collapsed": true | 7 "collapsed": true |
8 }, | 8 }, |
9 "outputs": [], | 9 "outputs": [], |
10 "source": [ | 10 "source": [ |
211 " plt.imshow(WW[:, :n_components], aspect='auto')\n", | 211 " plt.imshow(WW[:, :n_components], aspect='auto')\n", |
212 " plt.colorbar()\n", | 212 " plt.colorbar()\n", |
213 " plt.title('lda')\n", | 213 " plt.title('lda')\n", |
214 " plt.xlabel('components')\n", | 214 " plt.xlabel('components')\n", |
215 " plt.ylabel('features')\n", | 215 " plt.ylabel('features')\n", |
216 " plt.savefig('../data/lda_'+feat_labels[i]+'.pdf')\n", | |
216 " \n", | 217 " \n", |
217 " WW = ssm_feat.pca_transformer.components_.T\n", | 218 " WW = ssm_feat.pca_transformer.components_.T\n", |
218 " plt.figure()\n", | 219 " plt.figure()\n", |
219 " plt.imshow(WW[:, :n_components], aspect='auto')\n", | 220 " plt.imshow(WW[:, :n_components], aspect='auto')\n", |
220 " plt.colorbar()\n", | 221 " plt.colorbar()\n", |
221 " plt.title('pca')\n", | 222 " plt.title('pca')\n", |
222 " plt.xlabel('components')\n", | 223 " plt.xlabel('components')\n", |
223 " plt.ylabel('features')" | 224 " plt.ylabel('features')\n", |
225 " plt.savefig('../data/pca_'+feat_labels[i]+'.pdf')" | |
226 ] | |
227 }, | |
228 { | |
229 "cell_type": "markdown", | |
230 "metadata": {}, | |
231 "source": [ | |
232 "## export figure for LDA, PCA timbral components" | |
233 ] | |
234 }, | |
235 { | |
236 "cell_type": "code", | |
237 "execution_count": null, | |
238 "metadata": { | |
239 "collapsed": true | |
240 }, | |
241 "outputs": [], | |
242 "source": [ | |
243 "i = 3\n", | |
244 "print \"mapping \" + feat_labels[i]\n", | |
245 "inds = feat_inds[i]\n", | |
246 "ssm_feat = util_feature_learning.Transformer()\n", | |
247 "if min_variance is not None:\n", | |
248 " ssm_feat.fit_data(traindata[:, inds], trainlabels, n_components=len(inds), pca_only=True)\n", | |
249 " n_components = np.where(ssm_feat.pca_transformer.explained_variance_ratio_.cumsum()>min_variance)[0][0]+1\n", | |
250 " print n_components, len(inds)\n", | |
251 " ssm_feat.fit_lda_data(traindata[:, inds], trainlabels.ravel(), n_components=n_components)\n", | |
252 " print \"done fitting\"\n", | |
253 " WW = ssm_feat.lda_transformer.scalings_\n", | |
254 " plt.figure()\n", | |
255 " plt.imshow(WW[:, :n_components], aspect='auto')\n", | |
256 " plt.colorbar()\n", | |
257 " plt.title('lda')\n", | |
258 " plt.xlabel('components')\n", | |
259 " plt.ylabel('features')\n", | |
260 " y_loc = np.arange(10, 80, 20)\n", | |
261 " y_labs = ['mean(MFCC), mean(DELTA), std(MFCC), std(DELTA)']\n", | |
262 " plt.yticks(y_loc, y_labs, rotation='vertical')\n", | |
263 " plt.savefig('../data/lda_'+feat_labels[i]+'.pdf')\n", | |
264 "\n", | |
265 " WW = ssm_feat.pca_transformer.components_.T\n", | |
266 " plt.figure()\n", | |
267 " plt.imshow(WW[:, :n_components], aspect='auto')\n", | |
268 " plt.colorbar()\n", | |
269 " plt.title('pca')\n", | |
270 " plt.xlabel('components')\n", | |
271 " plt.ylabel('features')\n", | |
272 " y_loc = np.arange(10, 80, 20)\n", | |
273 " y_labs = ['mean(MFCC), mean(DELTA), std(MFCC), std(DELTA)']\n", | |
274 " plt.yticks(y_loc, y_labs, rotation='vertical')\n", | |
275 " plt.savefig('../data/pca_'+feat_labels[i]+'.pdf')" | |
224 ] | 276 ] |
225 }, | 277 }, |
226 { | 278 { |
227 "cell_type": "markdown", | 279 "cell_type": "markdown", |
228 "metadata": {}, | 280 "metadata": {}, |
416 "source": [ | 468 "source": [ |
417 "classifier_WW = ssm_feat.modelLDA.scalings_\n", | 469 "classifier_WW = ssm_feat.modelLDA.scalings_\n", |
418 "plt.figure()\n", | 470 "plt.figure()\n", |
419 "plt.imshow(classifier_WW, aspect='auto')\n", | 471 "plt.imshow(classifier_WW, aspect='auto')\n", |
420 "feat_lens = np.array([X_list[i].shape[1] for i in range(len(X_list))])\n", | 472 "feat_lens = np.array([X_list[i].shape[1] for i in range(len(X_list))])\n", |
421 "plt.yticks(np.cumsum(feat_lens), ['rhy', 'mel', 'mfc', 'chr']);\n", | 473 "#plt.yticks(np.cumsum(feat_lens), ['rhy', 'mel', 'mfc', 'chr']);\n", |
422 "plt.colorbar()\n", | 474 "plt.colorbar()\n", |
423 "plt.xlabel('components')\n", | 475 "plt.xlabel('components')\n", |
424 "plt.ylabel('features')\n", | 476 "plt.ylabel('features')\n", |
477 "boundaries = np.concatenate([[0], np.cumsum(feat_lens)])\n", | |
478 "y_loc = np.diff(boundaries) / 2.0 + boundaries[:-1]\n", | |
479 "y_labs = ['rhythm', 'melody', 'timbre', 'harmony']\n", | |
480 "plt.yticks(y_loc, y_labs, rotation='vertical')\n", | |
481 "plt.savefig('../data/pca_'+feat_labels[i]+'.pdf')\n", | |
482 "\n", | |
425 "\n", | 483 "\n", |
426 "classifier_WW = ssm_feat.modelSVM.support_vectors_.T\n", | 484 "classifier_WW = ssm_feat.modelSVM.support_vectors_.T\n", |
427 "plt.figure()\n", | 485 "plt.figure()\n", |
428 "plt.imshow(classifier_WW, aspect='auto')\n", | 486 "plt.imshow(classifier_WW, aspect='auto')\n", |
429 "feat_lens = np.array([X_list[i].shape[1] for i in range(len(X_list))])\n", | 487 "feat_lens = np.array([X_list[i].shape[1] for i in range(len(X_list))])\n", |
548 "file_extension": ".py", | 606 "file_extension": ".py", |
549 "mimetype": "text/x-python", | 607 "mimetype": "text/x-python", |
550 "name": "python", | 608 "name": "python", |
551 "nbconvert_exporter": "python", | 609 "nbconvert_exporter": "python", |
552 "pygments_lexer": "ipython2", | 610 "pygments_lexer": "ipython2", |
553 "version": "2.7.11" | 611 "version": "2.7.12" |
554 } | 612 } |
555 }, | 613 }, |
556 "nbformat": 4, | 614 "nbformat": 4, |
557 "nbformat_minor": 1 | 615 "nbformat_minor": 1 |
558 } | 616 } |