def fetchFeatures(filepath): print(filepath) paths = filepath.split("/") c = classes.index(paths[1]) # print(paths[1], c) vec = audio.showFeatures(filepath) return str(c) + "," + vec
def test(sc): files = ["sounds/flushing/20150227_193109-flushing-04.wav", "sounds/bike/20150227_193806-bici-14.wav", "sounds/blender/20150227_193606-licuadora-14.wav" ] rfmodel = RandomForestModel.load(sc, RF_PATH) dtmodel = DecisionTreeModel.load(sc, DT_PATH) print dtmodel.toDebugString() for f in files: vec = audio.showFeatures(f) testfeatures = Vectors.dense([float(x) for x in vec.split(' ')]) print(vec) pred = dtmodel.predict(testfeatures) print("DT Prediction is " + str(pred), classes[int(pred)]) pred = rfmodel.predict(testfeatures) print("RF Prediction is " + str(pred), classes[int(pred)])