{"id":1310,"date":"2023-03-25T10:12:45","date_gmt":"2023-03-25T02:12:45","guid":{"rendered":""},"modified":"2023-03-25T10:12:45","modified_gmt":"2023-03-25T02:12:45","slug":"\u4eba\u5de5\u667a\u80fd\u76d1\u7763\u5b66\u4e60(\u5206\u7c7b)","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1310.html","title":{"rendered":"\u4eba\u5de5\u667a\u80fd\u76d1\u7763\u5b66\u4e60(\u5206\u7c7b)"},"content":{"rendered":"
\n
\u4eba\u5de5\u667a\u80fd\u76d1\u7763\u5b66\u4e60(\u5206\u7c7b)\u8be6\u7ec6\u64cd\u4f5c\u6559\u7a0b<\/span>\n <\/div>\n \u5206\u7c7b\u6807\u7b7e\u540d\u79f0(target_names)<\/span>
\n \u5206\u7c7b<\/strong>\u3002\n <\/div>\n<\/span>\u5728Python\u4e2d\u6784\u5efa\u5206\u7c7b\u5668\u7684\u6b65\u9aa4<\/h2>\n
# Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
import <\/span>sklearn
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u4e73\u817a\u764c\u5a01\u65af\u5eb7\u661f\u8bca\u65ad\u6570\u636e\u5e93\u3002 \u6570\u636e\u96c6\u5305\u62ec\u6709\u5173\u4e73\u817a\u764c\u80bf\u7624\u7684\u5404\u79cd\u4fe1\u606f\uff0c\u4ee5\u53ca\u6076\u6027\u6216\u826f\u6027\u5206\u7c7b\u6807\u7b7e\u3002 \u8be5\u6570\u636e\u96c6\u5728569\u4e2a\u80bf\u7624\u4e0a\u5177\u6709569\u4e2a\u5b9e\u4f8b\u6216\u6570\u636e\uff0c\u5e76\u4e14\u5305\u62ec\u5173\u4e8e30\u4e2a\u5c5e\u6027\u6216\u7279\u5f81(\u8bf8\u5982\u80bf\u7624\u7684\u534a\u5f84\uff0c\u7eb9\u7406\uff0c\u5149\u6ed1\u5ea6\u548c\u9762\u79ef)\u7684\u4fe1\u606f\u3002 \u501f\u52a9\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5bfc\u5165Scikit-learn\u7684\u4e73\u817a\u764c\u6570\u636e\u96c6 -\n <\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
from <\/span>sklearn.datasets import <\/span>load_breast_cancer
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
data = load_breast_cancer()
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u5b9e\u9645\u6807\u7b7e(\u76ee\u6807)<\/span>
\n \u5c5e\u6027\/\u529f\u80fd\u540d\u79f0(feature_names)<\/span>
\n \u5c5e\u6027(\u6570\u636e)<\/span> <\/p>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
label_names = data['target_names'<\/span>]
labels = data['target'<\/span>]
feature_names = data['feature_names'<\/span>]
features = data['data'<\/span>]
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
print(label_names)
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
['malignant'<\/span> 'benign'<\/span>]
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
print(labels[0])
0
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
print(feature_names[0])
mean radius
print(features[0])
[ 1.79900000e+01 1.03800000e+01 1.22800000e+02 1.00100000e+03
1.18400000e-01 2.77600000e-01 3.00100000e-01 1.47100000e-01
2.41900000e-01 7.87100000e-02 1.09500000e+00 9.05300000e-01
8.58900000e+00 1.53400000e+02 6.39900000e-03 4.90400000e-02
5.37300000e-02 1.58700000e-02 3.00300000e-02 6.19300000e-03
2.53800000e+01 1.73300000e+01 1.84600000e+02 2.01900000e+03
1.62200000e-01 6.65600000e-01 7.11900000e-01 2.65400000e-01
4.60100000e-01 1.18900000e-01]
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
from <\/span>sklearn.model_selection import <\/span>train_test_split
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
train, test, train_labels, test_labels = train_test_split(features,labels,test_size = 0.40, random_state = 42)
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
from <\/span>sklearn.naive_bayes import <\/span>GaussianNB
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
gnb = GaussianNB()
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
model <\/span>= gnb.fit<\/span>(train, train_labels)
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
preds = gnb.predict<\/span>(test)
print(preds)
## -- \u7ed3\u679c\u5982\u4e0b
<\/span> [1 0 0 1 1 0 0 0 1 1 1 0 1 0 1 0 1 1 1 0 1 1 0 1 1 1 1 1 1
0 1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 0
0 1 1 0 0 1 1 1 0 0 1 1 0 0 1 0 1 1 1 1 1 1 0 1 1 0 0 0 0
0 1 1 1 1 1 1 1 1 0 0 1 0 0 1 0 0 1 1 1 0 1 1 0 1 1 0 0 0
1 1 1 0 0 1 1 0 1 0 0 1 1 0 0 0 1 1 1 0 1 1 0 0 1 0 1 1 0
1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0
1 1 0 1 1 1 1 1 1 0 0 0 1 1 0 1 0 1 1 1 1 0 1 1 0 1 1 1 0
1 0 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 0 0 1 1 0 1]
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
from <\/span>sklearn.metrics import <\/span>accuracy_score
print(accuracy_score(test_labels,preds))
0.951754385965
<\/span><\/code><\/pre>\n<\/p><\/div>\n<\/span>\u5728Python\u4e2d\u6784\u5efa\u5206\u7c7b\u5668<\/h2>\n
\n scikit learn<\/em>\u7684python\u5e93\u3002 \u5728scikit\u5b66\u4e60\u5305\u4e2d\uff0c\u6709\u4e09\u79cd\u7c7b\u578b\u7684\u6734\u7d20\u8d1d\u53f6\u65af\u6a21\u578b\u88ab\u79f0\u4e3aGaussian\uff0cMultinomial\u548cBernoulli\u3002\n <\/div>\n
\n Breast Cancer Wisconsin Diagnostic Database\u6570\u636e\u96c6\u3002 \u6570\u636e\u96c6\u5305\u62ec\u6709\u5173\u4e73\u817a\u764c\u80bf\u7624\u7684\u5404\u79cd\u4fe1\u606f\uff0c\u4ee5\u53ca\u6076\u6027\u6216\u826f\u6027\u5206\u7c7b\u6807\u7b7e\u3002 \u8be5\u6570\u636e\u96c6\u5728569\u4e2a\u80bf\u7624\u4e0a\u5177\u6709569\u4e2a\u5b9e\u4f8b\u6216\u6570\u636e\uff0c\u5e76\u4e14\u5305\u62ec\u5173\u4e8e30\u4e2a\u5c5e\u6027\u6216\u7279\u5f81(\u8bf8\u5982\u80bf\u7624\u7684\u534a\u5f84\uff0c\u7eb9\u7406\uff0c\u5149\u6ed1\u5ea6\u548c\u9762\u79ef)\u7684\u4fe1\u606f\u3002\u53ef\u4ee5\u4ecesklearn\u5305\u4e2d\u5bfc\u5165\u8fd9\u4e2a\u6570\u636e\u96c6\u3002\n <\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
import <\/span>sklearn
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
from <\/span>sklearn.datasets import <\/span>load_breast_cancer
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
data = load_breast_cancer()
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
label_names = data['target_names'<\/span>]
labels = data['target'<\/span>]
feature_names = data['feature_names'<\/span>]
features = data['data'<\/span>]
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
print(label_names)
<\/span><\/code><\/pre>\n<\/p><\/div>\n # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>