贝叶斯分类器

# 导入基础库
from sklearn.datasets import make_classification
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import train_test_split
# 导入朴素贝叶斯分类器
from naive_bayes_classifier import NaiveBayesClassifier
# 构造二元分类问题
X, y = make_classification(n_samples=1000, n_features=10, n_informative=10,
random_state=1111, n_classes=2, class_sep=2.5,
n_redundant=0)
# 划分训练数据集与测试数据集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1,
random_state=1111)
model = NaiveBayesClassifier()
# 进行模型拟合训练
model.fit(X_train, y_train)
# 进行模型预测
predictions = model.predict(X_test)[:, 1]
# 输出最终的测试结果
print('classification accuracy', roc_auc_score(y_test, predictions))