一、SVM 思想在解决回归问题上的体现

  • 回归问题的本质:找到一条直线或者曲线,最大程度的拟合数据点;
  • 怎么定义拟合,是不同回归算法的关键差异;
  1. 线性回归定义拟合方式:让所有数据点到直线的 MSE 的值最小;
  2. SVM 算法定义拟合的方式:在距离 Margin 的区域内,尽量多的包含样本点;
  • SVM 的思路解决回归问题:
  1. 在 Margin 区域内的样本点越多,则 Margin 区域越能够较好的表达样本数据点,此时,取 Margin 区域内中间的那条直线作为最终的模型;用该模型预测相应的样本点的 y 值;
  2. 在具体训练 SVM 算法模型解决回归问题时,提前指定 Margin 的大小,算法引入的超参数:ε,表示 Margin 区域的两条直线到区域中间的直线的距离,如图:
  • SVM 解决回归问题的思路与解决分类问题的思路相反,解决分类问题时,希望 Margin 区域内没有样本点或者样本点尽可能的少;
  • LinearSVC、SVC、LinearSVR、SVR
  1. LinearSVC:使用线性 SVM 的思路解决分类问题;
  2. SVC:使用非线性 SVM 的思路解决分类问题;(多项式核、高斯核)
  3. LinearSVR:使用线性 SVM 的思路解决回归问题;
  4. SVR:使用非线性 SVM 的思路解决回归问题;(使用不同的核函数)

二、scikit-learn 中的 SVM 算法:LinearSVR、SVR 解决回归问题

  • LinearSVR、SVR 的使用方式与 LinearSVC、SVC 一样

  • import numpy as np
    import matplotlib.pyplot as plt
    from sklearn import datasets boston = datasets.load_boston()
    X = boston.data
    y = boston.target from sklearn.model_selection import train_test_split
    X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=666) from sklearn.svm import LinearSVR
    from sklearn.svm import SVR
    from sklearn.preprocessing import StandardScaler
    from sklearn.pipeline import Pipeline def StandardLinearSVR(epsilon=0.1):
    return Pipeline([
    ('std_scaler', StandardScaler()),
    ('linearSVR', LinearSVR(epsilon=epsilon))
    # 此处使用超参数 C 的默认值;
    # 如果使用 SVR(),还需要调节参数 kernel;
    ]) svr = StandardLinearSVR()
    svr.fit(X_train, y_train)
    svr.score(X_test, y_test)
    # 准确率:0.6353520110647206

最新文章

  1. Torch7学习笔记(四)StochasticGradient
  2. Action中获取servletAPI对象的方法
  3. Android 显示意图激活另外一个Actitity
  4. WIN7实现多人远程一台电脑
  5. HDOJ--4786--Fibonacci Tree【生成树】
  6. the process cannot access the file because it is being used by another process
  7. What do `?i` and `?-i` in regex mean?
  8. ANTLR3
  9. struts2中根对象以及ognl .
  10. asp.net客户端IP跟踪
  11. sharepoint adfs Adding Claims to an Existing Token Issuer in SharePoint 2010
  12. 18.python关于mysql的api
  13. ubuntu install wiznote
  14. Python机器学习笔记:sklearn库的学习
  15. Windows Server 2008服务器上测试几个站点,改完host居然没有生效
  16. python简单实现目录对比
  17. 做 Excel 的 XML schema.xsd
  18. sublime text3 汉化
  19. 《Inside C#》笔记(一) .NET平台
  20. Vue.js 2.0 独立构建和运行时构建的区别

热门文章

  1. Linux下解压分包文件zip(zip/z01/z02)
  2. .NET CORE 动态调用泛型方法
  3. RabbitMQ死信队列
  4. R语言笔记005——计算描述性统计量
  5. MySql基础学习-mysql安装
  6. AppStore审核2.1被拒大礼包过审经历
  7. MFC 去掉CWnd的边框
  8. Spring Boot入门——json数据处理
  9. 14 Python 装饰器
  10. Spring_总结_03_装配Bean(四)_导入与混合配置