会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 128430个问题
人工智能/第六阶段:机器学习-线性分类/SVM支持向量机算法 1楼

import numpy as np
from sklearn import datasets
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import GridSearchCV
from sklearn.svm import SVC
import matplotlib.pyplot as plt

iris=datasets.load_iris()
# print(list(iris.keys()))
# print(iris['DESCR'])
# print(iris['feature_names'])
X=iris['data'][:,3:]
# print(X)
# print(iris['target'])
y=iris['target']
print(X)
print(y)

param_grid={'C':[1e3,5e3,1e4,5e4,1e5],
            'gamma':[0.0001,0.0005,0.001,0.005,0.01,0.1]}
model1=GridSearchCV(SVC(kernel='rbf',class_weight='balanced'),param_grid,cv=5)
model1=model1.fit(X,y)
model2=GridSearchCV(SVC(kernel='sigmoid',class_weight='balanced'),param_grid,cv=5)
model2=model2.fit(X,y)

test_labels=np.zeros(150)
test_labels[75:150]=1
result1=model1.predict(X)

test_labels=np.zeros(150)
test_labels[75:150]=1
result2=model2.predict(X)

print(confusion_matrix(test_labels,result1))
print(confusion_matrix(test_labels,result2))
model3=GridSearchCV(SVC(kernel='poly',class_weight='balanced'),param_grid,cv=5)
model3=model3.fit(X,y)

test_labels=np.zeros(150)
test_labels[75:150]=1
result3=model3.predict(X)
print(confusion_matrix(test_labels,result3))

model4=GridSearchCV(SVC(kernel='linear',class_weight='balanced'),param_grid,cv=5)
test_labels=np.zeros(150)
test_labels[75:150]=1
model4=model4.fit(X,y)
result4=model4.predict(X)
print(confusion_matrix(test_labels,result4))

改变四个核函数之后训练出来的模型为什么后面三个结果是一样的,这是巧合还是就是会出现这种情况

人工智能/第六阶段:机器学习-线性分类/SVM支持向量机算法 2楼
人工智能/第六阶段:机器学习-线性分类/SVM支持向量机算法 5楼
人工智能/第六阶段:机器学习-线性分类/SVM支持向量机算法 6楼
人工智能/第六阶段:机器学习-线性分类/Softmax回归 7楼
人工智能/第六阶段:机器学习-线性分类/Softmax回归 8楼
人工智能/第六阶段:机器学习-线性分类/Softmax回归 10楼
人工智能/第六阶段:机器学习-线性分类/SVM支持向量机算法 12楼
人工智能/第六阶段:机器学习-线性分类/Softmax回归 13楼
人工智能/第六阶段:机器学习-线性分类/SVM支持向量机算法 15楼

百战程序员微信公众号

百战程序员微信小程序

©2014-2024 百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637