{ "metadata": { "name": "", "signature": "sha256:87d9daf99e5dd04a4e931b27d00a174351903b19f38f0fc69d0190f437b45b74" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Classification of Separated Signals\n", "-----------------------------------\n", "\n", "Follow the K-NN example in Lab 1, but classify the *separated* signals.\n", "\n", "As in Lab 1, extract features from each training sample in the kick and snare drum directories.\n", "\n", "Train a K-NN model using the kick and snare drum samples:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import numpy as np\n", "\n", "labels = np.empty(20, np.int32)\n", "labels[0:9] = 1 # First 10 are the first sample type, e.g. snare\n", "labels[10:20] = 2 # Second 10 are the second sample type, e.g kick\n", "\n", "model_snare = KNeighborsClassifier(n_neighbors = 1)\n", "model.fit(scaledTrainingFeatures, labels.take(train_index, 0))\n", "model_output = model_snare.predict(scaledTestingFeatures)" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'KNeighborsClassifier' is not defined", "output_type": "pyerr", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mlabels\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;31m# Second 10 are the second sample type, e.g kick\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mmodel_snare\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mKNeighborsClassifier\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn_neighbors\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mscaledTrainingFeatures\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabels\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtake\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_index\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mmodel_output\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel_snare\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mscaledTestingFeatures\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mNameError\u001b[0m: name 'KNeighborsClassifier' is not defined" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Extract features from the drum signals that you separated in Lab 4 Section 1. \n", "\n", "3. Classify them using the K-NN model that you built.\n", "\n", " Does K-NN accurately classify the separated signals?\n", "\n", "4. Repeat for different numbers of separated signals (i.e., the parameter `K` in NMF). \n", "\n", "5. Overseparate the signal using `K = 20` or more. For those separated components that are classified as snare, add them together using `sum}. The listen to the sum signal. Is it coherent, i.e., does it sound like a single separated drum?\n", "\n", "...and more!\n", "\n", "* If you have another idea that you would like to try out, please ask me!\n", "* Feel free to collaborate with a partner. Together, brainstorm your own problems, if you want!\n", "\n", "Good luck!" ] } ], "metadata": {} } ] }