def main(): filename = "SPECT.csv" attributes = [] rows = [] with open(filename, 'r') as csvfile: csvreader = csv.reader(csvfile) attributes = next(csvreader) for row in csvreader: rows.append(row) k = 10 accuracy = [] summ = 0 for i in range(1, k + 1): after_fold = fold(rows, i, k) train_set = after_fold[0] test_set = after_fold[1] acc = train(train_set, attributes, test_set) accuracy.append(acc) print("The Accuracy for each fold is as follows : ") for i in accuracy: summ += i print(math.ceil(i)) summ = summ / k print("Average Accuracy : ", summ)
def main(): filename = "IRIS.csv" attributes = [] rows = [] with open(filename, 'r') as csvfile: csvreader = csv.reader(csvfile) attributes = next(csvreader) for row in csvreader: rows.append(row) print(len(attributes)) k = 10 #n=int(input("Enter the number of nodes at hidden layer : ")) n = 5 max_acc = 0 threshold = 0.1 for j in range(k): for i in range(1, k + 1): constant = i / 10 Rows = shuffle(rows) accuracy = [] Pre = [] Re = [] for i in range(1, k + 1): after_fold = fold(Rows, i, k) train_set = after_fold[0] test_set = after_fold[1] intermediate = train(train_set, test_set, attributes, constant, n, threshold) acc = intermediate[0] Precision = intermediate[1] Recall = intermediate[2] accuracy.append(acc) Pre.append(Precision) Re.append(Recall) acc_sum = 0 pre_sum = 0 re_sum = 0 for i in accuracy: print(i) for i in accuracy: acc_sum += i for i in Pre: pre_sum += i for i in accuracy: re_sum += i if (acc_sum / k) > max_acc: max_acc = acc_sum / k max_constant = constant print("For Learning Rate : ", constant, " Accuracy : ", acc_sum / k) print("Precision : ", pre_sum / k, " Recall : ", re_sum / k) print("--------------------------------------------") print("Maximum Accuracy : ", max_acc, " For learning rate : ", max_constant, " For Threshold : ", threshold) threshold += 0.1
def naive_bayes(k, rows, attributes): accuracy = [] for i in range(1, k + 1): after_fold = fold(rows, i, k) train_set = after_fold[0] test_set = after_fold[1] #print(len(train_set),"------------------") acc = train(train_set, attributes, test_set) accuracy.append(acc) summ = 0 for i in accuracy: summ += i return (summ / k)
def main(): filename="IRIS.csv" attributes=[] rows=[] with open(filename,'r') as csvfile: csvreader=csv.reader(csvfile) attributes=next(csvreader) for row in csvreader: rows.append(row) print(len(attributes)) k=10 acc_final=[] for i in range(1,k+1): constant=i/10 #constant=0.2 Rows=shuffle(rows) accuracy=[] Pre=[] Re=[] for i in range(1,k+1): after_fold=fold(rows,i,k) train_set=after_fold[0] test_set=after_fold[1] intermediate=train(train_set,test_set,attributes,constant) acc=intermediate[0] Precision=intermediate[1] Recall=intermediate[2] accuracy.append(acc) Pre.append(Precision) Re.append(Recall) #print(accuracy) acc_sum=0 pre_sum=0 re_sum=0 for i in accuracy: print(i) for i in accuracy: acc_sum+=i for i in Pre: pre_sum+=i for i in accuracy: re_sum+=i acc_final.append(acc_sum/k) print("For Learning Rate : ",constant," Accuracy : ",acc_sum/k) print("Precision : ",pre_sum/k," Recall : ",re_sum/k)