当前位置:网站首页>机器学习(三)多项式回归
机器学习(三)多项式回归
2022-08-11 07:38:00 【ViperL1】
一、原理
原型公式:
与多项式回归的区别:仅有一个自变量,次方数不同
适用情况:
属于线性回归的原因:线性并不是对于图线而言,是对于y是否能由自变量线性表达。
二、Python处理
从模型角度:多项式回归为非线性模型
①设置工作路径
②数据预处理
③多项式回归模型的建立和拟合
--用于参照的线性回归模型
from sklearn.Liner_model import LinearRegession
Lin_reg=LinearRegression() --线性回归对象
Lin_reg.fit(x,y) --拟合
--多项式回归模型
--矩阵转换
from sklearn.preprocessing import PoltnomialFeatures
poly_reg = PolnomialFeatures(degeree=2) --用于将自变量替换为其更高阶的矩阵(示例为2次)
x_poly = poly_reg.fit_transform(x) --转换
--模型构造
lin_reg_2 = LinearRegression()
Lin_reg_2.fit(x_poly,y)
--绘制模型
plt.sactter(x,y,color='red') --绘点
plt.plot(x,lin_reg.predict(x),color='blue') --线性回归图像
plt.title('真假?(线性模型)')
plt.xlabel('职位水平')
plt.ylabel('薪水')
--绘制模型
plt.sactter(x,y,color='red') --绘点
plt.plot(x,lin_reg_2.predict(poly_reg.fit_transform(x)),color='blue')
--多项式回归图像
plt.title('真假?(多项式模型)')
plt.xlabel('职位水平')
plt.ylabel('薪水')
模拟结果已经好了很多,但是拟合度还有待提高。可以通过升高多项式的次数来提升拟合度
poly_reg = PolnomialFeatures(degeree=4) --模型次数升高为4
由于x轴间距过大,导致图像不够平缓,可以通过缩小点间距使得图像更为平整
x_grid = np.arange(min(x),max(x),0.1) --最小值、最大值、步距
x_grid = x_grid.reshape(len(x_grid),1) --转换为矩阵
--绘制模型
plt.sactter(x,y,color='red') --绘点
plt.plot(x_grid,lin_reg_2.predict(poly_reg.fit_transform(x_grid)),color='blue')
--多项式回归图像
plt.title('真假?(多项式模型)')
plt.xlabel('职位水平')
plt.ylabel('薪水')
④进行预测
lin_reg.predict(6.5) --线性模型预测
--误差较大
lin_reg_2.predict(poly_reg.fit_transform(6.5))
--误差较小
边栏推荐
- 零基础SQL教程: 基础查询 05
- 基于微信小程序的租房小程序
- 通过记账,了解当月收支情况
- 1036 Programming with Obama (15 points)
- 2.1 - Gradient Descent
- 记录一些遇见的bug——Lombok和Mapstruct的冲突导致,A component required a bean of type ‘com.XXX.controller.converter.
- 【Pytorch】nn.ReLU(inplace=True)
- 零基础SQL教程: 主键、外键和索引 04
- 1076 Wifi Password (15 points)
- 【LeetCode】Summary of linked list problems
猜你喜欢
Do you know the basic process and use case design method of interface testing?
Distributed Lock-Redission - Cache Consistency Solution
Pico neo3在Unity中的交互操作
Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!
About # SQL problem: how to set the following data by commas into multiple lines, in the form of column display
3.1-Classification-probabilistic generative model
1003 我要通过 (20 分)
Hibernate 的 Session 缓存相关操作
3.1-分类-概率生成模型
TF中的四则运算
随机推荐
easyrecovery15数据恢复软件收费吗?功能强大吗?
零基础SQL教程: 基础查询 05
Square, multi-power, square root calculation in Tf
tf中自减操作;tf.assign_sub()
1051 Multiplication of Complex Numbers (15 points)
TF中的四则运算
1003 我要通过 (20 分)
经典论文-MobileNet V1论文及实践
CIKM 2022 AnalytiCup Competition: 联邦异质任务学习
囍楽云任务源码
3.1-Classification-probabilistic generative model
1.1-Regression
零基础SQL教程: 主键、外键和索引 04
1036 跟奥巴马一起编程 (15 分)
Tf中的平方,多次方,开方计算
欢迎加入sumarua网络安全交流社区
项目1-PM2.5预测
cdc连sqlserver异常对象可能有无法序列化的字段 有没有大佬看得懂的 帮忙解答一下
tf.cast(), reduce_min(), reduce_max()
2021-08-11 for循环结合多线程异步查询并收集结果