# Split into trainingX, trainingY, testX, testY

# shuffle these arrays so that training and test sets are randomized
print "shuffling the arrays"
allFeatures = random.sample(allFeatures, len(allFeatures)) 
allTargets = random.sample(allTargets, len(allTargets))

# percentage to train on
sampleSize = 0.1

trainSize = int(0.7*len(allFeatures)*sampleSize)
testSize = int(0.3*len(allFeatures)*sampleSize)
print "trainSize is: ", trainSize
print "testSize is: ", testSize

print "separating them into trainX, trainY, testX, testY"
trainX = allFeatures[:trainSize]
trainY = allTargets[:trainSize]
testX = allFeatures[trainSize:trainSize+testSize]
testY = allTargets[trainSize:trainSize+testSize]

print "done"

"""
Explanation: Split the Features and Targets into Training and Test Sets
End of explanation
"""


clf = svm.SVR()
clf.fit(trainX, trainY) 
predictions = clf.predict(testX)

"""
Explanation: 🤖 Machine Learning (with sklearn)
End of explanation
"""


def calculateError(prediction, actual):
    return (predicted-actual)/actual

percentageErrors = []
for i, prediction in enumerate(predictions):
    actual = testY[i][0]
    percentageError = (prediction-actual)/actual
    percentageErrors.append(percentageError)

overallError = np.sum(percentageErrors) / len(percentageErrors)

print "Overall error was: " + str(overallError*100) + "%"

"""
Explanation: Calculate the Percentage of Error
Go through each example and calculate the percentage of error. Add this percentage of error to an array. Then use this array to calculate the overall percentage of error within the predicted test set.
End of explanation
"""


