SVM-非线性

本文探讨了SVM中非线性内核的使用,通过比较linear和rbf内核在分类任务上的性能,发现rbf内核表现更优。接着,用SVR进行回归任务,分析了epsilon参数的影响。最后,对比了SVC、LinearSVC、SGDClassifier在速度和精度上的差异,展示了在大规模数据集上SGDClassifier的高效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SVM非线性内核:

  • 多项式  poly
  • 径向基函数  rbf
  • Sigmod
  • 高级定制核

一、对比linear和rbf内核的性能区别

#比较几种核及参数,挑选出性能最好的svm模型
#载入数据
from sklearn import datasets
digits = datasets.load_digits()
X,y = digits.data, digits.target
#数据区分测试集和训练集,并将数据标准化
from sklearn.cross_validation import train_test_split, cross_val_score
from sklearn.preprocessing import MinMaxScaler
# We keep 30% random examples for test
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=101)
# We scale the data in the range [-1,1]
scaling = MinMaxScaler(feature_range=(-1, 1)).fit(X_train)
X_train = scaling.transform(X_train)
X_test  = scaling.transform(X_test)

from sklearn.svm import SVC
from sklearn.grid_search import GridSearchCV
import numpy as np
learning_algo = SVC(class_weight='balanced', random_state=101)
search_space = [{'kernel': ['linear'], 'C': np.logspace(-3, 3, 7)},
                {'kernel': ['rbf'], 'degree':[2,3,4], 'C':np.logspace(-3, 3, 7), 'gamma': np.logspace(-3, 2, 6)}]
gridsearch = GridSearchCV(learning_algo, param_grid=search_space, scoring='accuracy', refit=True, cv=10, n_jobs=-1)
gridsearch.fit(X_train,y_train)
cv_performance = gridsearch.best_score_
test_performance = gridsearch.score(X_test, y_test)
print ('Cross-validation ac

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值