资源简介
Python 语言调用SVR算法实现回归分析,代码示例,线性回归是利用数理统计中的回归分析,来确定两种或两种以上变量间相互依赖的定量关系的一种统计分析方法,运用十分广泛。
在统计学中,线性回归(Linear Regression)是利用称为线性回归方程的最小平方函数对一个或多个自变量和因变量之间关系进行建模的一种回归分析。这种函数是一个或多个称为回归系数的模型参数的线性组合。只有一个自变量的情况称为简单回归,大于一个自变量情况的叫做多元回归。

代码片段和文件信息
# -*- coding: UTF-8 -*-
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt
###############################################################################
# Generate sample data
#X = np.sort(5 * np.random.rand(40 1) axis=0) #产生40组数据,每组一个数据,axis=0决定按列排列,=1表示行排列
#y =[0 0 0 0 0 2 1 0 3 0 1 1 4 1 0 0 4 1 5 3 3 1]
y = [0.5 0.3333333333333333 0.75 1.0 1.5 1.5714285714285714 3.0 2.6666666666666665 2.4 2.1818181818181817 2.0833333333333335 1.9230769230769231 1.7857142857142858 1.7333333333333334 2.6875 2.8823529411764706 3.611111111111111 4.105263157894737 4.2 4.380952380952381]
Y = []
X =[[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[10]
[11]
[12]
[13]
[14]
[15]
[16]
[17]
[18]
[19]
[20]
#[21]
#[22]
]
#np.sin(X).ravel() #np.sin()输出的是列,和X对应,ravel表示转换成行
#X = np.sort(5 * np.random.rand(40 1) axis=0)
print(X)
for i in y :
Y.append(np.log(i))
y = Y
###############################################################################
# Add noise to targets
#y[::5] += 3 * (0.5 - np.random.rand(8))
###############################################################################
# Fit regression model
svr_rbf10 = SVR(kernel=‘rbf‘C=100 gamma=10.0)
svr_rbf1 = SVR(kernel=‘rbf‘ C=100 gamma=0.1)
svr_rbf1 = SVR(kernel=‘rbf‘ C=100 gamma=0.1)
#svr_lin = SVR(kernel=‘linear‘ C=1e3)
#svr_poly = SVR(kernel=‘poly‘ C=1e3 degree=3)
y_rbf10 = svr_rbf10.fit(X y).predict(X)
y_rbf1 = svr_rbf1.fit(X y).predict(X)
#y_lin = svr_lin.fit(X y).predict(X)
#y_poly = svr_poly.fit(X y).predict(X)
###############################################################################
# look at the results
lw = 2 #line width
plt.scatter(X y color=‘darkorange‘ label=‘data‘)
plt.hold(‘on‘)
plt.plot(X y_rbf10 color=‘navy‘ lw=lw label=‘RBF gamma=10.0‘)
plt.plot(X y_rbf1 color=‘c‘ lw=lw label=‘RBF gamma=1.0‘)
#plt.plot(X y_lin color=‘c‘ lw=lw label=‘Linear model‘)
#plt.plot(X y_poly color=‘cornflowerblue‘ lw=lw label=‘Polynomial model‘)
plt.xlabel(‘data‘)
plt.ylabel(‘target‘)
plt.title(‘Support Vector Regression‘)
plt.legend()
plt.show()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2232 2018-10-25 14:11 SVR_1.py
----------- --------- ---------- ----- ----
2232 1
相关资源
- 易语言python支持库
- Python-BDD100K大规模多样化驾驶视频数据
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
评论
共有 条评论