コード例 #1
0
ファイル: multiClassSvm.py プロジェクト: narleras/CS221
def features1():

    trainingSet, trainingComposers, numTrainingComposers, numTrainingPieces = loadData.loadTrainingFiles()
    trainingFeatureVectors, trainingFeatureNames, trainingComposerNames = extractFeatures.initFeatureVectors(4, trainingSet, len(labels)+1)

    testingSet, testingComposers, numTestingComposers, numTestingPieces = loadData.loadTestingFiles()
    testingFeatureVectors, testingFeatureNames, testingComposerNames = extractFeatures.initFeatureVectors(4, testingSet, len(labels)+1)

    nameList = list()
    for name in trainingFeatureNames:
        nameList.append(name)

    for name in testingFeatureNames:
        nameList.append(name)

    print 'begin convertion'
    trainingData = np.zeros((len(trainingFeatureVectors), len(nameList)))
    testingData = np.zeros((len(testingFeatureVectors), len(nameList)))

    for author in range(len(trainingFeatureVectors)):
        for feature in trainingFeatureVectors[author]:
            trainingData[author][nameList.index(feature)] = trainingFeatureVectors[author][feature]
    for author in range(len(testingFeatureVectors)):
        for feature in testingFeatureVectors[author]:
            testingData[author][nameList.index(feature)] = testingFeatureVectors[author][feature]
    print 'done convertion'
    #data = np.array([[featureVectors[author][feature] for feature in sorted(featureVectors[author])] for author in range(len(featureVectors))])

    predictions = bench_svm(trainingData, testingData, trainingComposerNames)

    printStatistics(predictions, testingComposerNames)
コード例 #2
0
ファイル: multiClassSvm.py プロジェクト: narleras/CS221
def features2():
    trainingSet, trainingComposers, numTrainingComposers, numTrainingPieces = loadData.loadTrainingFiles()
    trainingData, trainingComposerNames = extractFeatures.initFeatureVectors(trainingSet, numTrainingComposers, numTrainingPieces)

    testingSet, testingComposers, numTestingComposers, numTestingPieces = loadData.loadTestingFiles()
    testingFeatureVectors, testingComposerNames = extractFeatures.initFeatureVectors(testingSet, numTestingComposers, numTestingPieces)

    #trainingComposerNames = [0, 1, 2, 3, 4]
    #testingComposerNames = [0, 1, 2, 3, 4]
    predictions = bench_svm(trainingData, testingFeatureVectors, trainingComposerNames)

    printStatistics(predictions, testingComposerNames, numTrainingComposers)