Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list problem
#1
how can i improve the code below, the problem lies with how y_pred is stored which i cant add to total. the idea is to calculate accuracy over 150 training examples and mean error rate.

if __name__ == "__main__":
    dataset = "car.data"
    attributes = ['buying', 'maint', 'doors', 'persons', 'lug_boot', 'safety']
    target = 'acceptability'
    samples = 150
    total = 0.0
    k=0
    while (k<6):
        k = input("Enter the number of neighbours: ")
        k = int(k)
        for i in range(samples):
            y_pred = []
            temp = KNN(X_train,y_train,X_test,y_pred,k)
            y_pred = np.asarray(y_pred)
        acc = accuracy_score(y_test, y_pred)
        total = total + temp
        acc = total/samples
        error_rate = 100 - avg_acc
        cm = confusion_matrix(y_test,y_pred)
        cr = classification_report(y_test,y_pred)
        print(acc)total = total + temp
        print("Accuracy:", +acc)
        print("Avg Accuracy:" +avg_acc)
        print(cm)
        print(cr)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with "Number List" problem on HackerRank Pnerd 5 2,034 Apr-12-2022, 12:25 AM
Last Post: Pnerd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020