Advertisement
dzocesrce

[VI] Cryotherapy

Jan 24th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. #Naiven Baes so neprekinati domeni
  2. import os
  3. os.environ['OPENBLAS_NUM_THREADS'] = '1'
  4. from sklearn.preprocessing import OrdinalEncoder
  5. from sklearn.naive_bayes import GaussianNB
  6.  
  7. if __name__ == '__main__':
  8.  
  9.     dataset = [['1', '35', '12', '5', '1', '100', '0'], ['1', '29', '7', '5', '1', '96', '1'],
  10.                ['1', '50', '8', '1', '3', '132', '0'], ['1', '32', '11.75', '7', '3', '750', '0'],
  11.                ['1', '67', '9.25', '1', '1', '42', '0'], ['1', '41', '8', '2', '2', '20', '1'],
  12.                ['1', '19', '8', '8', '1', '160', '1']]
  13.  
  14.     dataset_float=[]
  15.     for row in dataset:
  16.         row_df= [float(el) for el in row]
  17.         dataset_float.append(row_df)
  18.  
  19.  
  20.     train_set= dataset_float[:int(0.85*len(dataset_float))]
  21.     train_x= [row[:-1] for row in train_set]
  22.     train_y= [row[-1] for row in train_set]
  23.  
  24.     test_set = dataset_float[int(0.85 * len(dataset_float)):]
  25.     test_x= [row[:-1] for row in test_set]
  26.     test_y= [row[-1] for row in test_set]
  27.  
  28.     classifier = GaussianNB()
  29.     classifier.fit(train_x, train_y)
  30.  
  31.     accuracy=0
  32.     for i in range(len(test_set)):
  33.         if classifier.predict([test_x[i]])[0] == test_y[i]:
  34.             accuracy+=1
  35.  
  36.     print(accuracy/len(test_set))
  37.     entry=[float(el) for el in input().split(' ')]
  38.  
  39.     print(int(classifier.predict([entry])[0]))
  40.     print(classifier.predict_proba([entry]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement