Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. from sklearn.datasets import load_breast_cancer
  2. from sklearn.naive_bayes import GaussianNB
  3. from sklearn.metrics import accuracy_score
  4. from sklearn.cross_validation import train_test_split
  5.  
  6.  
  7.  
  8. def bayes_gaussian():
  9.     '''
  10.    Klasyfikator: http://scikit-learn.org/stable/modules/naive_bayes.html
  11.    '''
  12.  
  13.     # pobranie danych (to samo co z tego uci)
  14.     cancer_data = load_breast_cancer()
  15.  
  16.     # przypisanie cech i wyjscia do zmiennych
  17.     x = cancer_data.data  # cechy
  18.     y = cancer_data.target  # wyjście
  19.  
  20.     # podział na zbiór uczący i testowy -> test_size to procent ktory maja zajmowac dane testowe z calego zbioru (max=1.0)
  21.     x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=.2)
  22.  
  23.     # utworzenie klasyfikatora
  24.     clf = GaussianNB()
  25.  
  26.     # uczenie klasyfikatora danymi uczącymi
  27.     clf.fit(x_train, y_train)
  28.  
  29.     # testowanie klasyfikatora
  30.     predictions = clf.predict(x_test)
  31.  
  32.     # obliczenie skuteczności (max = 1.0)
  33.     accuracy = accuracy_score(y_test, predictions)
  34.     print("Accuracy score: {}".format(accuracy))
  35.  
  36.  
  37. if __name__ == '__main__':
  38.     bayes_gaussian()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement