{ "metadata": { "name": "", "signature": "sha256:d9eb3269c1983f409941f02e3a32bcda113cabce09e7af16f8bf6df8deab397e" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Here, you build a classifier with Scikit-Learn for use in 6b. The You'll want to read in Oscar's original data as an array of bitwise note vectors, and from there build the RBM to predict chords (the y's, perhaps build the chord bank and assign a unique number to each). After that, given a note vector (maybe plural?), you should be able to predict the chords for a note (notes?).\n", "\n", "This is for Oscar's musical data. The next step is to do the classification for your n-gram model." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from collections import defaultdict\n", "import pandas as pd\n", "import numpy as np\n", "import scipy.sparse\n", "import random, cPickle" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "# Extract chords into unique ids, e.g. 1, 2, 3, 4, 5\n", "allchords = defaultdict() # remember that it's a hash table\n", "with open(\"oscar2chords_extract.txt\", 'rb') as f:\n", " for ix, line in enumerate(f):\n", " items = line.split()\n", " allchords[ix] = items\n", "assert len(allchords) == len(set(allchords)) # ensure no duplicate chords" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "# Read in Oscar's data.\n", "vectors = []\n", "notedata = pd.read_csv(open(\"oscar2notes.txt\", 'rb'), skiprows=2)\n", "allnotes = []\n", "for note, octave in zip(notedata[\"Note/Rest\"], notedata[\"Octave\"]):\n", " allnotes.append(\"%s%s\" % (note, octave))\n", "\n", "print \"Number of notes (# of samples for RBM): \", len(notedata)\n", "notedata.head()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Number of notes (# of samples for RBM): 1344\n" ] }, { "html": [ "
\n", " | Note/Rest | \n", "Octave | \n", "Len | \n", "Offset | \n", "
---|---|---|---|---|
0 | \n", "B | \n", "3 | \n", "0.500000 | \n", "12.625 | \n", "
1 | \n", "A | \n", "5 | \n", "0.250000 | \n", "15.000 | \n", "
2 | \n", "F | \n", "4 | \n", "3.125000 | \n", "16.000 | \n", "
3 | \n", "G | \n", "4 | \n", "0.666667 | \n", "20.625 | \n", "
4 | \n", "F | \n", "4 | \n", "1.250000 | \n", "23.875 | \n", "
5 rows \u00d7 4 columns
\n", "