Advertisement
metalni

VI Treta Labaratoriska - 2

Jun 30th, 2021
1,269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 29.04 KB | None | 0 0
  1. '__main__':
  2.     x_1 = int(input())
  3.     x_2 = int(input())
  4.  
  5.     # 1
  6.     test_set_1 = dataset[:x_1]
  7.     test_x_1 = [x[:-1] for x in test_set_1]
  8.     test_y_1 = [x[-1] for x in test_set_1]
  9.  
  10.     train_set_1 = dataset[x_1:]
  11.     train_x_1 = [x[:-1] for x in train_set_1]
  12.     train_y_1 = [x[-1] for x in train_set_1]
  13.  
  14.     # 2
  15.     test_set_2 = dataset[:x_2]
  16.     test_x_2 = [x[:-1] for x in test_set_2]
  17.     test_y_2 = [x[-1] for x in test_set_2]
  18.  
  19.     train_set_2 = dataset[x_2:]
  20.     train_x_2 = [x[:-1] for x in train_set_2]
  21.     train_y_2 = [x[-1] for x in train_set_2]
  22.  
  23.     classifier_1 = MLPClassifier(3, activation='relu', learning_rate_init=0.003, max_iter=200, random_state=0)
  24.     classifier_2 = MLPClassifier(3, activation='relu', learning_rate_init=0.003, max_iter=200, random_state=0)
  25.  
  26.     classifier_1.fit(train_x_1, train_y_1)
  27.     classifier_2.fit(train_x_2, train_y_2)
  28.  
  29.     accuracy_1 = 0
  30.     for i in range(0, len(test_set_1)):
  31.         predict = classifier_1.predict([test_x_1[i]])
  32.         if predict[0] == test_set_1[i][-1]:
  33.             accuracy_1 += 1
  34.     final_acc_1 = accuracy_1 / len(test_set_1)
  35.     print(f"Tochnost model1: {final_acc_1}")
  36.  
  37.     accuracy_2 = 0
  38.     for i in range(0, len(test_set_2)):
  39.         predict = classifier_2.predict([test_x_2[i]])
  40.         if predict[0] == test_set_2[i][-1]:
  41.             accuracy_2 += 1
  42.  
  43.     final_acc_2 = accuracy_2 / len(test_set_2)
  44.     print(f"Tochnost model2: {final_acc_2}")
  45.  
  46.     if final_acc_1 > final_acc_2:
  47.         print("Prviot model ima pogolema tochnost")
  48.     elif final_acc_2 > final_acc_1:
  49.         print("Vtoriot model ima pogolema tochnost")
  50.     else:
  51.         print("Dvata modeli imaat ednakva tochnost")
  52.  
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement