0
我在python下面一本關於機器學習,我只是不明白這個代碼:如何製造和使用樸素貝葉斯分類器與Scikit
import numpy as np
import matplotlib.pyplot as plt
from sklearn.naive_bayes import GaussianNB
from sklearn import cross_validation
from utilities import visualize_classifier
# Input file containing data
input_file = 'data_multivar_nb.txt'
# Load data from input file
data = np.loadtxt(input_file, delimiter=',')
X, y = data[:, :-1], data[:, -1]
# Create Naive Bayes classifier
classifier = GaussianNB()
# Train the classifier
classifier.fit(X, y)
# Predict the values for training data
y_pred = classifier.predict(X)
# Compute accuracy
accuracy = 100.0 * (y == y_pred).sum()/X.shape[0]
print("Accuracy of Naive Bayes classifier =", round(accuracy, 2), "%")
我只是有幾個問題:
data [:,:-1]和data [:,-1]是做什麼的? 輸入文件的形式:
2.18,0.57,0
4.13,5.12,1
9.87,1.95,2
4.02,-0.8,3
1.18,1.03,0
4.59,5.74,1
如何計算精度的部分工作? 什麼是X.shape [0]? 最後,我如何使用分類器來預測新值的y?