import numpy as np
import pandas as pd
from rp_feature_io import load_or_analyze_features, concatenate_features, sorted_feature_subset
from classes_io import *
from rp_classify import *
# READ FEATURES
#input_path = 'features/zicotest3'
#input_path = 'features/new_mood_6Xcut' # pure mood assignments
#input_path = 'features/zico+new_mood'
#input_path = 'features/test_thursday'
#input_path = 'features/zico+new_mood+thursday_cut'
#input_path = 'features/zico+new_mood+thursday+set2'
#input_path = 'features/test_friday1'
input_path = 'features/zico+new_mood+thursday+set2+friday1_cut'
ids, feat = load_or_analyze_features(input_path)
# NOTE: Feature files contain audio file names WITH extension. To match with CSV we do:
ids = strip_filenames(ids) # in feature data
Read: rp: 447 audio file vectors, 1440 dimensions Read: ssd: 447 audio file vectors, 168 dimensions Read: rh: 447 audio file vectors, 60 dimensions
# READ CLASS DATA
#filename = '../Desktop/annotations/analyse_sample_sep_moods_only_edited.csv'
#filename = '../Desktop/annotations/new mood special.csv'
#filename = '../Desktop/annotations/zico+new_mood.csv'
#filename = '../Desktop/annotations/test_thursday.csv'
#filename = '../Desktop/annotations/zico+new_mood+thursday_cut.csv'
#filename = '../Desktop/annotations/zico+new_mood+thursday+set2.csv'
#filename = '../Desktop/annotations/test_friday1_compare+corrected.csv'
#filename = '../Desktop/annotations/zico+new_mood+thursday+set2+friday1.csv'
filename = '../Desktop/annotations/ALL_knowledge_WeekDec.csv'
# MusiMap: for new mood special we have X/2 entries which mean like the mood is half present. we treat it as positive at the moment
dataframe = read_multi_class_file(filename, pos_labels=('x','X/2'))
file_ids_classfile = list(dataframe.index)
categories = dataframe.columns.values.tolist()
Categories in CSV file: fluid, saccadé, lyric, chaotic, quiet, water, air, wood, ground, metal, fire
dataframe
fluid | saccadé | lyric | chaotic | quiet | water | air | wood | ground | metal | fire | |
---|---|---|---|---|---|---|---|---|---|---|---|
nom | |||||||||||
01 - Erykah Badu - No More Trouble | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
01 44 Blues | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
01 A Foggy Day | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
01 AAMosambiquetravellplan | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 |
01 Animus Vox | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
01 Beep Beep Beep | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
01 Chega de Saudade | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
01 Chrysalide | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
01 GRINNING IN YOUR FACE | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
01 Halleluja, I Love Her So | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
01 Hear My Train Comin' | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 |
01 Hungarian Polka | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
01 Jai Hanuman! | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 |
01 Killing Me Softly With His Song | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
01 Los Aretes De La Luna | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
01 Privilege | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
01 Reve 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
01 Scream & Shout (feat. Britney Spears) | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
01 Since I've Been Loving You | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 |
01 Space Oddity | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
01 Sweet Mercy | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
01 Tannhauser Ouverture | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
01 Umbrella [Feat. Jay-Z] | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
01 We No Who U R | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 |
01A Vivaldi | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
02 (Sittin' On) The Dock Of The Bay | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 |
02 Choeur De Femmes - Ujaj | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 |
02 Give 'Em Hell, Kid | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
02 Jumpin' Jack Flash | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
02 Mika - Relax, Take It Easy | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
02 Rehab | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
02 Spoken | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 1 |
03 Be Like You | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
03 Cutting Class | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
03 Gangsta | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
03 I Love Paris Too | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
03 Italian Shoes | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
03 Lucky To Be Me | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
03 Suite Meets | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
04 - The Computers - Hot Damnocles | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
04 Chippie | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
04 Je Sais Que Tu Sais | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
04 The Touch Of Your Lips | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
04B Penny Lane | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
05 Devil Take My Soul | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 |
05 Don't Miss Me | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
05 I'm Waiting For The Day | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
05 La musse | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
05 LA Woman | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
05B The Fool On The Hill | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
06 - Mc Lyte - Jammin | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 |
06 - The Computers - Rhythm Revue | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
06 Cocaine | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 |
06 Making Plans For Nigel | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
06 Powderfinger | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 |
06 Rhythm & Rhyme | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 |
07 - Satisfy My Soul Jah-Jah | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
07 Brown Sugar | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
07 Choeur D'Hommes - Manimbon | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 |
07 Dub Experience II | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
505 rows × 11 columns
# MATCHING CLASS AND AUDIO FEATURE IDS
ids_matched = match_filenames(file_ids_classfile, ids)
# Note: sorting or not sorting changes the results of cross-validation :-(
ids_matched = sorted(ids_matched)
505 files in class file 447 files in feature file(s) 445 files matching in class definition but not in audio feature files: 02 Struck Down 06 Blancasnow 1-05 Song No. 1 04 Tus Ojos...! 07 Their Memories 10 bad day (live) bourgoisie blues 05A The Honeydripper 06 Marijuana Defenders 02 marijuana in my brain instru Can't Hold Us 03 Giorgio by Moroder 08 Sensuality 12 My Blues 01 Country Road (Live) 09 What Do I Have To Do T Prove My Love To You sony mix move like jagger 07 No Thing On Me (Cocaine Song) 13 Exodus 02 The Game of Love 04 Inabox 04 Penetration Unsquare dance (114x79) 2-05 Birth1 12 マンモスの行進 6-02 Silence [Instrumental] 05 I'll Go Through It's My Birthday 17 La Bamba _ Twist And Shout (Medley) 02 hypofull of love Show Yourself _ Tun Ova Riddim _ June 2013 09 Cry Me A River Cargo de nuit 03 Croatian Rebel 01 GRINNING IN YOUR FACE 07 Susie Q 06 Mannish Boy printemps 08 Take A Look (At Yourself) 03 Samba Vexillographica 09 Maria Callas 04 Apollo exofavela6 exofavela5 19 Luna de Margarita Happy (Official Music Video)-16 Blurred Lines ft. T.I., Pharrell 05 Dusk braz girl 12 (I'm a) Roadrunner Heroes 07 Shaouk 07 Every Teardrop Is a Waterfall 04 Joy, Joy [Remastered_ 2001] 2-12 I'm Sitting On Top Of The World 05 Hey Bo Diddley 05 Evil And A Heathen 12 The Barn 11 Memphis in audio feature files but not in class definition: 04 I Want To Be Happy The Walking Dead - Générique Saison 5 [OFFICIEL]
# create a new reduced dataframe that contains only the matched files (in the matched order)
dataframe_cut = dataframe.ix[ids_matched]
# get numeric classes from the class dataframe
classes_num = dataframe_cut.as_matrix()
# PREPARE FEATURES
# cut & resort the features according to matched ids (subset, if files are missing in class file)
feat_sorted = sorted_feature_subset(feat, ids, ids_matched)
# select the feature types to use + combine
#feature_types = ('ssd','rh')
#feature_types = ('rp')
#feature_types = ('rp','ssd')
feature_types = ('rp','ssd','rh')
feat_merged = concatenate_features(feat_sorted, feature_types)
# standardize
features, scaler = standardize(feat_merged)
# debug
print "After matching & concatenation:", features.shape[0], "files,", features.shape[1], "feature dimensions"
After matching & concatenation: 445 files, 1668 feature dimensions
# DIRECT MULTI CLASS CLASSIFICATION with sklearn
from sklearn import preprocessing, svm
from sklearn.multiclass import OneVsRestClassifier
from sklearn.svm import SVC
#model = svm.SVC(kernel='linear')
# we use this syntax as it supports multi-class classification
model = OneVsRestClassifier(SVC(kernel='linear'))
# with probabilities?
#model = svm.SVC(probability=True, random_state=0)
# cross_validation.cross_val_score(clf, X, y, scoring='log_loss')
model.fit(features,classes_num)
OneVsRestClassifier(estimator=SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape=None, degree=3, gamma='auto', kernel='linear', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False), n_jobs=1)
model = train_model(features, classes_num, print_accuracy = True)
Accuracy on train set: 100.00 %
classes_num.shape
(391, 11)
# CROSS VALIDATION
# we iterate over the categories in class file columns here
from sklearn import cross_validation
for c in range(len(categories)):
cls = classes_num[:,c]
a= cross_validation.cross_val_score(model, features,cls, scoring='accuracy', cv=10)
mean_acc = np.mean(a)
print categories[c], mean_acc * 100
fluid 72.108974359 saccadé 75.132928475 lyric 72.3782051282 chaotic 71.4429824561 quiet 91.3755060729 water 64.2115384615 air 67.532388664 wood 73.258097166 ground 67.2820512821 metal 72.3677462888 fire 89.298582996
print "Input Audio Analysis for Model:", input_path
print "Input Expert Class Annotations:", filename
print "Feature Types used: " + ", ".join(feature_types).upper()
print
Input Audio Analysis for Model: features/zico+new_mood+thursday+set2+friday1_cut Input Expert Class Annotations: ../Desktop/annotations/zico+new_mood+thursday+set2+friday1.csv Feature Types used: RP, SSD, RH
# CLASSIFICATION LOOP
# CUSTOM MULTI CLASS CLASSIFICATION self-written
crossval_outfile = 'output/tom_music_crossval.csv'
fil = open(crossval_outfile,'w')
fil.write("Input Audio Analysis for Model:\t" + input_path + '\n')
fil.write("Feature Types used:\t" + ", ".join(feature_types).upper() + '\n')
fil.write("Input Expert Class Annotations:\t" + filename + '\n\n')
fil.write("CROSS-VALIDATION (10 folds):\n\n")
models = {} # store all models in a dict
labelenc = {} # store all labelencoders in a dict
# separate between 2 groups
rhythmic_moods = categories[0:5]
mood_groups = categories[5:11]
# accumulate accuracy for groups and overall
mean_acc_rhythm = 0
mean_acc_moodgr = 0
mean_acc_overall = 0
model_file_stub = "models/model"
print "Input Audio Analysis for Model:", input_path
print "Input Expert Class Annotations:", filename
print "Feature Types used: " + ", ".join(feature_types).upper()
print
# iterate over the categories (= columns)
for cat in categories:
print "Class: " + cat + ":\t",
class_labels = dataframe_cut.ix[:,cat].tolist()
# number of positive class labels
n_examples = sum(c == 1 for c in class_labels)
print n_examples, ' files\t',
fil.write(cat + "\t" + str(n_examples) + 'files\t')
# convert to numeric classes
classes_num, labelencoder = classes_to_numeric(class_labels, verbose=False, return_encoder = True)
# train model
# with_probabilities is needed when we want to output probabilities at test time
# but it takes much longer (as it does internal cross-validation) and results may also be different
model = train_model(features, classes_num, print_accuracy = False)
# store in memory (dict)
models[cat] = model
labelenc[cat] = labelencoder
# cross validate accuracy
acc = cross_validate(model, features, classes_num, folds=10)
#print "Avg Accuracy (%d folds): %2.2f %% \t (stddev: %2.2f)" % (len(acc), (np.mean(acc)*100), np.std(acc)*100)
mean_acc = np.mean(acc)
print "%2.2f %%" % (mean_acc*100)
fil.write("%2.2f %%".format((mean_acc*100)) + '\n')
mean_acc_overall += mean_acc
if cat in rhythmic_moods: mean_acc_rhythm += mean_acc
if cat in mood_groups: mean_acc_moodgr += mean_acc
# save model
save_model(model_file_stub + "." + cat + ".pkl", model, scaler, labelencoder)
mean_acc_rhythm /= len(rhythmic_moods)
mean_acc_moodgr /= len(mood_groups)
mean_acc_overall /= len(categories)
print 'AVG ACCURACY Rhythmic Moods:\t%2.2f %%' % (mean_acc_rhythm*100)
print 'AVG ACCURACY Mood Groups:\t%2.2f %%' % (mean_acc_moodgr*100)
print 'AVG ACCURACY OVERALL: \t%2.2f %%' % (mean_acc_overall*100)
print
print "written to", crossval_outfile
fil.close()
Input Audio Analysis for Model: features/zico+new_mood+thursday+set2+friday1_cut Input Expert Class Annotations: ../Desktop/annotations/zico+new_mood+thursday+set2+friday1.csv Feature Types used: RP, SSD, RH Class: fluid: 0 files 71.70 % Class: saccadé: 0 files 77.75 % Class: lyric: 0 files 71.20 % Class: chaotic: 0 files 73.05 % Class: quiet: 0 files 89.90 % Class: water: 0 files 66.99 % Class: air: 0 files 68.73 % Class: wood: 0 files 73.46 % Class: ground: 0 files 69.41 % Class: metal: 0 files 70.56 % Class: fire: 0 files 88.56 % AVG ACCURACY Rhythmic Moods: 76.72 % AVG ACCURACY Mood Groups: 72.95 % AVG ACCURACY OVERALL: 74.67 % written to output/tom_music_crossval.csv
# TESTING
#test_path = 'features/test-eau'
#test_path = 'features/test_new_thomas'
#test_path = "features/zicotest3"
#test_path = "features/test_wednesday"
#test_path = 'features/thursday_verify'
#test_path = 'features/test_friday2'
test_path = 'features/tom_music'
result_filename = 'output/test_tom_music.csv'
ids_test, feat_test = load_or_analyze_features(test_path)
# SELECT OR CONCATENATE FEATURES
feat_test_merged = concatenate_features(feat_test, feature_types)
# SCALE FEATURES LIKE TRAINING DATA
features_to_classify = scaler.transform(feat_test_merged)
Read: rp: 7 audio file vectors, 1440 dimensions Read: ssd: 7 audio file vectors, 168 dimensions Read: rh: 7 audio file vectors, 60 dimensions
# CLASSIFY (new method: sklearn)
predictions = model.predict(features_to_classify)
def predictions_to_list(predictions, categories):
'''translate a binary multi-class prediction matrix to a list of strings containing the positively
predicted labels
predictions: numpy array with 0/1 predictions
categories: list of category labels for each column in predictions (number of columns must match number of list entries)
returns: dict with one entry per file id, containing a list of string values for positively predicted classes
'''
# initialize results dict with empty list so entries are contained that do not have a single positive prediction
results = {}
for f in ids_test:
results[f] = []
# iterate over columns and store the positive predictions in a list
for c in range(predictions.shape[1]):
cat = categories[c]
for f,p in zip(ids_test,predictions[:,c]):
if p == 1:
if not f in results:
results[f] = [cat] # create new 1-entry list entry in results dict
else:
results[f].append(cat) # append to existing list
return results
# PRINT RESULTS
results = predictions_to_list(predictions, categories)
print "Input Audio Analysis for Model:", input_path
print "Feature Types used: " + ", ".join(feature_types).upper()
print "Input Expert Class Annotations:", filename
print "Audio Files to Test:", test_path
print "Output file:", result_filename
print
print "PREDICTIONS:"
for k in results.keys():
print k, '\t', ", ".join(results.get(k))
Input Audio Analysis for Model: features/zico+new_mood+thursday+set2 Feature Types used: RP, SSD, RH Input Expert Class Annotations: ../Desktop/annotations/zico+new_mood+thursday+set2.csv Audio Files to Test: features/test_friday2 Output file: output/test_friday2_input_zico+new_mood+thursday+set2.csv PREDICTIONS: 1-05 Song No. 1.aif water 12 The Barn.mp3 saccadé, air 05 Hey Bo Diddley.mp3 fluid, water, air, fire 04 Joy, Joy [Remastered_ 2001].mp3 quiet, water, fire 6-02 Silence [Instrumental].wav lyric, quiet, water, air, metal 06 Mannish Boy.wav chaotic, wood, ground 05 Evil And A Heathen.mp3 saccadé, chaotic, wood, ground 04 Tus Ojos...!.wav quiet 11 Memphis.wav fluid, water, wood, metal 12 My Blues.mp3 19 Luna de Margarita.mp3 lyric, water, air, wood, ground 12 (I'm a) Roadrunner.mp3 saccadé, water, air, wood 03 Croatian Rebel.mp3 fluid, chaotic, air 05A The Honeydripper.aif lyric, air, wood, ground 07 Every Teardrop Is a Waterfall.mp3 saccadé, chaotic, wood, ground 06 Blancasnow.wav fluid, quiet, water, air, fire 05 I'll Go Through.wav wood 04 Apollo.mp3 saccadé, wood 08 Take A Look (At Yourself).wav fluid, saccadé, chaotic, water, wood, metal 17 La Bamba _ Twist And Shout (Medley).wav saccadé, chaotic, wood 09 Maria Callas.aif fire braz girl.mp3 fluid, saccadé, water, metal 07 Susie Q.mp3 chaotic, water, wood 04 Inabox.mp3 saccadé, quiet 2-05 Birth1.aif fluid, saccadé, chaotic, water, wood 09 Cry Me A River.mp3 fluid, water, metal 02 Struck Down.mp3 fluid, saccadé, wood 06 Marijuana Defenders.mp3 fluid, quiet 02 The Game of Love.mp3 fluid, saccadé, chaotic, water, metal 05 Dusk.wav quiet, fire 07 Their Memories.mp3 lyric, water 01 Country Road (Live).wav fluid, water, wood 07 No Thing On Me (Cocaine Song).mp3 saccadé, water, wood 10 bad day (live).mp3 fluid, water, wood, metal 03 Giorgio by Moroder.mp3 fluid, saccadé, water, wood, metal 02 marijuana in my brain instru.mp3 fluid, water, ground 03 Samba Vexillographica.mp3 wood, fire 08 Once In A While.wav fluid, lyric, air, wood, metal Heroes.mp3 chaotic, quiet, ground, fire 13 Exodus.mp3 saccadé, lyric, air, wood 04 Penetration.wav saccadé, lyric, chaotic, wood, ground, metal 07 Shaouk.wav lyric, water, air, metal 08 Sensuality.wav lyric, water, air
# CLASSIFY (old method: each category separately)
# initialize results dict with empty list so entries are contained that do not have a single positive prediction
results = {}
for f in ids_test:
results[f] = []
# if a prediction was made for a certain category, add its name to the dict list
for cat in categories:
predictions = classify(models[cat], features_to_classify, labelenc[cat])
for f,p in zip(ids_test,predictions):
#print f, "\t", p
if p == 1:
if not f in results:
results[f] = [cat] # create new 1-entry list entry in results dict
else:
results[f].append(cat) # append to existing list
results
{'01 - Asian Dub Foundation - Flyover.m4a': ['saccad\xc3\xa9', 'lyric', 'water', 'air', 'wood'], '03 TV on the radio - Dancing Choose.mp3': ['wood'], '04 - Paul Kalkbrenner - Sky And Sand (Radio Edit).mp3': ['saccad\xc3\xa9', 'chaotic', 'ground', 'metal', 'fire'], 'Johann Strauss - Emperor Waltz op. 437.mp3': ['lyric', 'fire'], 'Morcheeba - Big Calm.mp3': ['fluid', 'saccad\xc3\xa9', 'lyric', 'air', 'wood'], 'Nine Inch Nails - Hurt.mp3': ['quiet', 'water', 'fire'], 'Prodigy - Voodoo People.mp3': ['saccad\xc3\xa9', 'lyric', 'chaotic', 'air', 'wood', 'ground']}
# SAVE to output file
fil = open(result_filename,'w')
fil.write("Input Audio Analysis for Model:\t" + input_path + '\n')
fil.write("Feature Types used:\t" + ", ".join(feature_types).upper() + '\n')
fil.write("Input Expert Class Annotations:\t" + filename + '\n')
fil.write("Audio Files to Test:\t" + test_path + '\n')
fil.write("PREDICTIONS:\n\n")
for k in results.keys():
fil.write(k + '\t' + "\t".join(results.get(k)) + '\n')
fil.close()
# TEST WITH PROBABILITIES
cat = categories[0]
print cat
model = models[cat]
print model.classes_
print labelenc[cat].inverse_transform(model.classes_)
pred = model.predict(features_to_classify)
prob = model.predict_proba(features_to_classify)
dec = model.decision_function(features_to_classify)
for c, p, d in zip(pred,prob,dec):
print c, p, d
# NOT UNDERSTANDABLE
#fluid
#[0 1]
#['n' 'x']
#1 [ 0.60997072 0.39002928] 0.777435842855
#0 [ 0.76297632 0.23702368] -0.831269278351
#1 [ 0.56023258 0.43976742] 1.24380788124
#1 [ 0.59362058 0.40637942] 0.933793985289
#0 [ 0.77118897 0.22881103] -0.934217910963
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-118-83cde1792b52> in <module>() 8 print labelenc[cat].inverse_transform(model.classes_) 9 pred = model.predict(features_to_classify) ---> 10 prob = model.predict_proba(features_to_classify) 11 dec = model.decision_function(features_to_classify) 12 /usr/local/lib/python2.7/dist-packages/sklearn/svm/base.pyc in predict_proba(self) 608 datasets. 609 """ --> 610 self._check_proba() 611 return self._predict_proba 612 /usr/local/lib/python2.7/dist-packages/sklearn/svm/base.pyc in _check_proba(self) 575 def _check_proba(self): 576 if not self.probability: --> 577 raise AttributeError("predict_proba is not available when " 578 " probability=False") 579 if self._impl not in ('c_svc', 'nu_svc'): AttributeError: predict_proba is not available when probability=False
fluid [0 1] ['n' 'x']