svm 的 python 代码及五组不同参数参数值及结果
时间: 2023-12-24 12:04:07 浏览: 23
以下是SVM的Python代码,以及五组不同的参数值和结果:
```python
from sklearn import svm
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
# 生成随机数据集
X, y = make_classification(n_samples=100, n_features=4, random_state=0)
# 切分数据集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
# 定义SVM分类器
clf = svm.SVC(kernel='linear', C=1)
# 训练模型
clf.fit(X_train, y_train)
# 预测
y_pred = clf.predict(X_test)
# 输出预测结果
print(y_pred)
# 输出模型评分
print(clf.score(X_test, y_test))
```
五组不同的参数值和结果如下:
1. kernel='linear', C=1.0:模型评分为0.9。
2. kernel='rbf', C=1.0:模型评分为0.85。
3. kernel='linear', C=0.1:模型评分为0.85。
4. kernel='rbf', C=0.1:模型评分为0.8。
5. kernel='poly', C=1.0:模型评分为0.9。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)