文章目录

  • 非线性样本
  • Sklearn回归汇总
    • 决策树
    • 随机森林
    • 高斯过程
  • Keras神经网络
  • LSTM

非线性样本

from matplotlib import pyplot as mp
y = [.4187, .0964, .0853, .0305, .0358, .0338, .0368, .0222, .0798, .1515]
x = [[i]for i in range(len(y))]
mp.scatter(x, y, s=99)
mp.show()

Sklearn回归汇总


import matplotlib.pyplot as mp
# 训练集
y = [.27, .16, .06, .036, .044, .04, .022, .017, .022, .014, .017, .02, .019, .017, .011, .01, .03, .05, .066, .09]
ly, n = len(y), 100
x = [[i / ly]for i in range(ly)]
# 待测集
w = [[i / n] for i in range(n)]
# # x轴范围
# max_x = 1
# x, w = [[i[0]*max_x] for i in x], [[i[0]*max_x] for i in w]def modeling(models):for i in range(len(models)):print(models[i].__name__)# 建模、拟合model = models[i]()model.fit(x, y)# 预测z = model.predict(w)# 可视化mp.subplot(3, 4, i + 1)mp.title(models[i].__name__, size=10)mp.xticks(())mp.yticks(())mp.scatter(x, y, s=11, color='g')mp.scatter(w, z, s=1, color='r')mp.show()from sklearn.neighbors import KNeighborsRegressor, RadiusNeighborsRegressor
from sklearn.ensemble import GradientBoostingRegressor, AdaBoostRegressor,\RandomForestRegressor, BaggingRegressor, ExtraTreesRegressor, VotingRegressor
from sklearn.tree import DecisionTreeRegressor, ExtraTreeRegressor
from sklearn.svm import SVR
from sklearn.neural_network import MLPRegressor
from sklearn.gaussian_process import GaussianProcessRegressor
modeling([KNeighborsRegressor, RadiusNeighborsRegressor,GradientBoostingRegressor, AdaBoostRegressor, RandomForestRegressor, BaggingRegressor, ExtraTreesRegressor,# VotingRegressor,DecisionTreeRegressor, ExtraTreeRegressor,SVR, MLPRegressor, GaussianProcessRegressor
])from sklearn.linear_model import LinearRegression, RANSACRegressor, ARDRegression, HuberRegressor, TheilSenRegressor,\SGDRegressor, PassiveAggressiveRegressor, Lasso, ElasticNet, Ridge, BayesianRidge, Lars
modeling([LinearRegression, RANSACRegressor, ARDRegression, HuberRegressor, TheilSenRegressor,SGDRegressor, PassiveAggressiveRegressor, Lasso, ElasticNet, Ridge, BayesianRidge, Lars
])

决策树

import matplotlib.pyplot as mp
# 训练集
y = [.4187, .0964, .0853, .0305, .0358, .0338, .0368, .0222, .0798, .1515]
x = [[i]for i in range(len(y))]
# 待测集
w = [[i / 100 * len(y)] for i in range(100)]def modeling(models):n = len(models)for i in range(n):# 建模、拟合models[i].fit(x, y)# 预测z = models[i].predict(w)# 可视化mp.subplot(1, n, i + 1)mp.scatter(x, y, s=22, color='g')mp.scatter(w, z, s=2, color='r')mp.show()from sklearn.tree import DecisionTreeRegressor
modeling([DecisionTreeRegressor(max_depth=1),DecisionTreeRegressor(max_depth=2),DecisionTreeRegressor(max_depth=3),DecisionTreeRegressor(max_depth=4),DecisionTreeRegressor(),
])

随机森林

import matplotlib.pyplot as mp
# 训练集
y = [.4187, .0964, .0853, .0305, .0358, .0338, .0368, .0222, .0798, .1515]
x = [[i]for i in range(len(y))]
# 待测集
w = [[i / 100 * len(y)] for i in range(100)]def modeling(models):n = len(models)for i in range(n):# 建模、拟合models[i].fit(x, y)# 预测z = models[i].predict(w)# 可视化mp.subplot(1, n, i + 1)mp.scatter(x, y, s=22, color='g')mp.scatter(w, z, s=2, color='r')mp.show()from sklearn.ensemble import RandomForestRegressor
modeling([RandomForestRegressor(max_depth=1),RandomForestRegressor(max_depth=2),RandomForestRegressor(),
])

高斯过程

高斯过程回归:使用高斯过程先验对数据进行回归分析的非参数模型(non-parameteric model)
算法特征:计算开销大,通常用于低维和小样本的回归问题
应用领域:时间序列分析、图像处理和自动控制等

from sklearn.gaussian_process import GaussianProcessRegressor
import matplotlib.pyplot as mp, random
# 创建样本
a = [199, 188, 170, 157, 118, 99, 69, 44, 22, 1, 5, 9, 15, 21, 30, 40, 50, 60, 70, 79, 88, 97, 99, 98, 70, 46, 39, 33]
for e, y in enumerate((a, [a[i//2]+random.randint(0, 30) for i in range(len(a)*2)])):# 待测集ly, n = len(y), 2000w = [[i / n * 1.2 - .1] for i in range(n)]# 建模、拟合、预测model = GaussianProcessRegressor()model.fit([[i/ly]for i in range(ly)], y)z = model.predict(w)# 可视化mp.subplot(1, 2, e + 1)mp.yticks(())mp.bar([i/ly for i in range(ly)], y, width=.7/ly)mp.scatter(w, z, s=1, color='r')
mp.show()

Keras神经网络

from matplotlib import pyplot
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import Adam# 训练集
y = [.27, .16, .06, .036, .044, .04, .022, .017, .022, .014, .017, .02, .019, .017, .011, .01, .03, .05, .066, .09]
x = list(range(len(y)))
# 待测集
n = 200
w = [i/n*len(y) for i in range(n)]# 建模
model = Sequential()
model.add(Dense(units=10, input_dim=1, activation='sigmoid'))
model.add(Dense(units=1, activation='sigmoid'))
# 编译、优化
model.compile(optimizer=Adam(), loss='mse')for i in range(10):# 训练model.fit(x, y, epochs=2500, verbose=0)print(i, 'loss', model.evaluate(x, y, verbose=0))# 预测z = model.predict(w)# 可视化pyplot.subplot(2, 5, i + 1)pyplot.xticks(())pyplot.yticks(())pyplot.scatter(x, y)  # 样本点pyplot.scatter(w, z, s=2)  # 预测线
pyplot.show()

LSTM

https://blog.csdn.net/Yellow_python/article/details/86668140

Python非线性回归相关推荐

  1. python 非线性回归_机器学习入门之菜鸟之路——机器学习之非线性回归个人理解及python实现...

    本文主要向大家介绍了机器学习入门之菜鸟之路--机器学习之非线性回归个人理解及python实现,通过具体的内容向大家展现,希望对大家学习机器学习入门有所帮助. 梯度下降:就是让数据顺着梯度最大的方向,也 ...

  2. python多元非线性回归_Python利用神经网络解决非线性回归问题实例详解

    本文实例讲述了Python利用神经网络解决非线性回归问题.分享给大家供大家参考,具体如下: 问题描述 现在我们通常使用神经网络进行分类,但是有时我们也会进行回归分析. 如本文的问题: 我们知道一个生物 ...

  3. python:绘制GAM非线性回归散点图和拟合曲线

    作者:CSDN @ _养乐多_ 本文将介绍使用python语言绘制广义线性模型(Generalized Additive Model,GAM)非线性回归散点图和拟合曲线.并记录了计算RMSE.ubRM ...

  4. python非线性回归分析_sklearn实现非线性回归模型

    sklearn实现非线性回归模型 前言: sklearn实现非线性回归模型的本质是通过线性模型实现非线性模型,如何实现呢?sklearn就是先将非线性模型转换为线性模型,再利用线性模型的算法进行训练模 ...

  5. python 非线性多项式拟合_用python进行非线性回归-有什么简单的方法可以更好地拟合这些数据?...

    此示例代码使用具有两个形状参数(a和b)和偏移项(不影响曲率)的表达式.方程为"y=1.0/(1.0+exp(-a(x-b)))+Offset",参数值a=2.1540318329 ...

  6. python的几种非线性回归

    前一阵子有人和我吐槽过matlab内置的几个线性数据拟合工具满足不了需求,今天正好看到了一个关于使用scipy进行非线性回归的工具使用方法,写下来备忘. Theory Given pairs:{(ti ...

  7. python多元非线性回归_利用Python进行数据分析之多元线性回归案例

    线性回归模型属于经典的统计学模型,该模型的应用场景是根据已知的变量(自变量)来预测某个连续的数值变量(因变量).例如,餐厅根据每天的营业数据(包括菜谱价格.就餐人数.预定人数.特价菜折扣等)预测就餐规 ...

  8. python多元非线性拟合csdn_手写算法-Python代码实现非线性回归

    生成非线性数据集 前面我们介绍了Python代码实现线性回归,今天,我们来聊一聊当数据呈现非线性时,这时我们继续用线性表达式去拟合,显然效果会很差,那我们该怎么处理?继续上实例(我们的代码里用到的数据 ...

  9. python多元非线性回归_day-13 python库实现简单非线性回归应用

    一.概率 在引入问题前,我们先复习下数学里面关于概率的基本概念 概率:对一件事发生的可能性衡量 范围:0<=P<=1 计算方法:根据个人置信区间:根据历史数据:根据模拟数据. 条件概率:B ...

最新文章

  1. 推荐2020年度最佳的23个的机器学习项目(附源代码)
  2. openstack queens 版本 linux bridge起不来的解决办法
  3. java连连看源代码在哪_连连看java源代码
  4. TypeScript中的枚举类型
  5. java分页模板_java 分页模型的模板
  6. Spring Boot中使用MyBatis注解配置详解
  7. TortoiseGit功能介绍
  8. .net与java之争
  9. Oracle 无备份情况下的恢复--控制文件/数据文件
  10. CSND自定义模块管理
  11. 实对称矩阵的特征值求法_特征值的最大值与最小值
  12. eos 源代码学习笔记二
  13. 美国专利客体适格性判断标准浅析
  14. EPSON TM U220串口打印机乱码
  15. “空城计”不灵了,产城融合才有未来
  16. .net支付宝沙箱二维码支付
  17. 帝国cms 标签php,帝国CMS ecmsinfo万能标签
  18. html5 vue bootstrap学习报告
  19. 非对称加密下RSA在Java的简明教程
  20. pmos 电源开关电路_如何验证开关电源电路

热门文章

  1. @Kubernetes(k8s)
  2. [网络安全学习篇1]:windowsxp、windows2003、windows7、windows2008系统部署(千峰网络安全视频笔记)
  3. 2019年10月计算机系统结构答案,2019年计算机系统结构复习题.doc
  4. 扣丁软件测试基础知识,苹果无线充电线圈揭秘,iphone8无线充电线圈介绍
  5. 【Niagara Vykon N4】物联网学习 02 照明控制
  6. JAVA基础知识练习(减肥计划、逢七过、不死神兔、百钱百鸡、数组元素求和、数组内容相同、查找、反转、评委打分)
  7. VDA19颗粒清洁度测试方法及要素
  8. python爬取网站m3u8视频,将ts解密成mp4,合并成整体视频
  9. linux微信原生版2.1.5,优麒麟版重新打包,适用于debian内核系统
  10. 利用for语句,编程输出如下图形:* *** *****