这一章又完了~
一,代码
from sklearn.datasets import make_blobs
import matplotlib.pyplot as plt
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
X, y = make_blobs(n_samples=200, random_state=1, centers=2, cluster_std=5)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=68)
gnb = GaussianNB()
gnb.fit(X_train, y_train)
predict_proba = gnb.predict_proba(X_test)
print('预测准确率形态:{}'.format(predict_proba.shape))
print(predict_proba[:5])
svc = SVC().fit(X_train, y_train)
dec_func = svc.decision_function(X_test)
print(dec_func[:5])
# plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.cool, edgecolors='k')
# plt.show()
二,效果
C:\Users\ccc\AppData\Local\Programs\Python\Python38\python.exe D:/Code/Metis-Org/app/service/time_series_detector/algorithm/ai_test.py
预测准确率形态:(50, 2)
[[0.98849996 0.01150004]
[0.0495985 0.9504015 ]
[0.01648034 0.98351966]
[0.8168274 0.1831726 ]
[0.00282471 0.99717529]]
[-1.36071347 1.53694862 1.78825594 -0.96133081 1.81826853]
Process finished with exit code 0
网友评论