**Following is my python code**

```
import csv
import random
import math

def separateByClass(dat):
    separated = {}
    for i in range(len(dat)):
        vector = dat[i]
        if (vector[-1] not in separated):
            separated[vector[-1]] = []
        separated[vector.pop()].append(vector)
    return separated

def splitDataset(dataset, splitRatio):
    trainSize = int(len(dataset) * splitRatio)
    trainSet = []
    copy = list(dataset)
    while len(trainSet) < trainSize:
        index = random.randrange(len(copy))
        trainSet.append(copy.pop(index))
    return [trainSet, copy]

def mean(numbers):
    return sum(numbers)/float(len(numbers))

def stdev(numbers):
    avg = mean(numbers)
    variance = sum([pow(x-avg,2) for x in numbers])/float(len(numbers)-1)
    return math.sqrt(variance)

def summarize(dataset):
    summaries = [(mean(attribute), stdev(attribute)) for attribute in zip(*dataset)]
    del summaries[-1]
    return summaries

def summarizeByClass(dataset):
    separated = separateByClass(dataset)
    summaries = {}
    for classValue, instances in separated.iteritems():
        summaries[classValue] = summarize(instances)
    return summaries

def calculateProbability(x, mean, stdev):
    exponent = math.exp(-(math.pow(x-mean,2)/(2*math.pow(stdev,2))))
    return (1 / (math.sqrt(2*math.pi) * stdev)) * exponent

def calculateClassProbabilities(summaries, inputVector):
    probabilities = {}
    for classValue, classSummaries in summaries.iteritems():
        probabilities[classValue] = 1
        for i in range(len(classSummaries)):
            mean, stdev = classSummaries[i]
            x = inputVector[i]
            probabilities[classValue] *= calculateProbability(x, mean, stdev)
    return probabilities

def predict(summaries, inputVector):
    probabilities = calculateClassProbabilities(summaries, inputVector)
    bestLabel, bestProb = None, -1
    for classValue, probability in probabilities.iteritems():
        if bestLabel is None or probability > bestProb:
            bestProb = probability
            print bestProb
            bestLabel = classValue
    return bestLabel

def getPredictions(summaries, testSet):
    predictions = []
    for i in range(len(testSet)):
        result = predict(summaries, testSet[i])
        predictions.append(result)
    return predictions

def getAccuracy(testSet, predictions):
    correct = 0
    for i in range(len(testSet)):
        if testSet[i][-1] == predictions[i]:
            correct += 1
    return (correct/float(len(testSet))) * 100.0

def main(str):
    #clustered data
    filename = 'a.csv'
    lines = csv.reader(open(filename, "rb"))
    a=list(lines)
    for i in range(len(a)):
        a[i]=[float(x) for x in a[i]]

    #main data
    filename = 'h.csv'
    lines = csv.reader(open(filename, "rb"))
    data = list(lines)
    for i in range(len(data)):
        data[i] = [float(x) for x in data[i]]
        data[i].append(a[i][1])

    s = separateByClass(data)

    count=True
    for key,values in s.items():
        if count:
            a=values
            count=False
        b=values

    trainingSet1, testSet1 = splitDataset(a, 0.67)
    trainingSet, testSet = splitDataset(b, 0.67)
    trainingSet.extend(trainingSet1)
    testSet.extend(testSet1)
    summaries = summarizeByClass(trainingSet)
    testset=str
    predictions = predict(summaries, testSet)
    accuracy = getAccuracy(testSet, predictions)
    result = predict(summaries, testset)
    returnValue.append(accuracy)
    returnValue.append(result)
    print returnValue

def ab():
    st=[70.0,1.0,4.0,130.0,322.0,0.0,2.0,109.0,0.0,2.4,2.0,3.0,3.0,1.0]
    a=main(st)
    return a
ab()

```

> 
> The two files used a.csv and h.csv contains 2 and 14 colums respectively.
>  The code runs perfectly fine if the accuracy was not computed.
>  ie only when the predict() is used.
> 
> 
> 

It gives the error as follows.

```
Traceback (most recent call last):
File "D:\nowedit\P.py", line 126, in <module>
ab()
File "D:\nowedit\P.py", line 124, in ab
a=main(st)
File "D:\nowedit\P.py", line 115, in main
predictions = predict(summaries, testSet)
File "D:\nowedit\P.py", line 60, in predict
probabilities = calculateClassProbabilities(summaries, inputVector)
File "D:\nowedit\P.py", line 56, in calculateClassProbabilities
probabilities[classValue] *= calculateProbability(x, mean, stdev)
File "D:\nowedit\P.py", line 46, in calculateProbability
exponent = math.exp(-(math.pow(x-mean,2)/(2*math.pow(stdev,2))))
TypeError: unsupported operand type(s) for -: 'list' and 'float'

```