回归算法-概述

2023-11-15

回归算法-概述 (Regression Algorithms - Overview)

回归概论 (Introduction to Regression)

Regression is another important and broadly used statistical and machine learning tool. The key objective of regression-based tasks is to predict output labels or responses which are continues numeric values, for the given input data. The output will be based on what the model has learned in training phase. Basically, regression models use the input data features (independent variables) and their corresponding continuous numeric output values (dependent or outcome variables) to learn specific association between inputs and corresponding outputs.

回归是另一个重要且广泛使用的统计和机器学习工具。 基于回归的任务的主要目标是针对给定的输入数据,预测输出标签或响应(连续的数值)。 输出将基于模型在训练阶段学到的知识。 基本上,回归模型使用输入数据特征(独立变量)及其对应的连续数值输出值(因变量或结果变量)来学习输入与对应输出之间的特定关联。

回归模型的类型 (Types of Regression Models)

Regression models are of following two types −

回归模型具有以下两种类型-

Simple regression model − This is the most basic regression model in which predictions are formed from a single, univariate feature of the data.

简单回归模型 -这是最基本的回归模型,其中预测是根据数据的单变量特征形成的。

Multiple regression model − As name implies, in this regression model the predictions are formed from multiple features of the data.

多元回归模型 -顾名思义,在此回归模型中,预测是根据数据的多个特征形成的。

用Python构建一个回归器 (Building a Regressor in Python)

Regressor model in Python can be constructed just like we constructed the classifier. Scikit-learn, a Python library for machine learning can also be used to build a regressor in Python.

可以像构造分类器一样构造Python中的Regressor模型。 Scikit-learn,一个用于机器学习的Python库,也可以用于在Python中构建一个回归器。

In the following example, we will be building basic regression model that will fit a line to the data i.e. linear regressor. The necessary steps for building a regressor in Python are as follows −

在下面的示例中,我们将构建基本的回归模型,该模型将使一条线适合数据,即线性回归。 在Python中构建回归器的必要步骤如下-

步骤1:导入必要的python包 (Step 1: Importing necessary python package)

For building a regressor using scikit-learn, we need to import it along with other necessary packages. We can import the by using following script −

为了使用scikit-learn构建回归器,我们需要将其与其他必要的软件包一起导入。 我们可以使用以下脚本导入-


import numpy as np
from sklearn import linear_model
import sklearn.metrics as sm
import matplotlib.pyplot as plt

步骤2:导入数据集 (Step 2: Importing dataset)

After importing necessary package, we need a dataset to build regression prediction model. We can import it from sklearn dataset or can use other one as per our requirement. We are going to use our saved input data. We can import it with the help of following script −

导入必要的程序包后,我们需要一个数据集来构建回归预测模型。 我们可以从sklearn数据集中导入它,也可以根据需要使用其他一个。 我们将使用保存的输入数据。 我们可以在以下脚本的帮助下导入它-


input = r'C:\linear.txt'

Next, we need to load this data. We are using np.loadtxt function to load it.

接下来,我们需要加载此数据。 我们正在使用np.loadtxt函数加载它。


input_data = np.loadtxt(input, delimiter=',')
X, y = input_data[:, :-1], input_data[:, -1]

步骤3:将数据整理到训练和测试集中 (Step 3: Organizing data into training & testing sets)

As we need to test our model on unseen data hence, we will divide our dataset into two parts: a training set and a test set. The following command will perform it −

由于我们需要在看不见的数据上测试模型,因此,我们将数据集分为两部分:训练集和测试集。 以下命令将执行它-


training_samples = int(0.6 * len(X))
testing_samples = len(X) - num_training

X_train, y_train = X[:training_samples], y[:training_samples]

X_test, y_test = X[training_samples:], y[training_samples:]

步骤4:模型评估和预测 (Step 4: Model evaluation & prediction)

After dividing the data into training and testing we need to build the model. We will be using LineaRegression() function of Scikit-learn for this purpose. Following command will create a linear regressor object.

将数据划分为训练和测试后,我们需要构建模型。 为此,我们将使用Scikit-learn的LineaRegression()函数。 以下命令将创建一个线性回归对象。


reg_linear= linear_model.LinearRegression()

Next, train this model with the training samples as follows −

接下来,使用以下训练样本训练该模型:


reg_linear.fit(X_train, y_train)

Now, at last we need to do the prediction with the testing data.

现在,最后我们需要对测试数据进行预测。


y_test_pred = reg_linear.predict(X_test)

第5步:绘图和可视化 (Step 5: Plot & visualization)

After prediction, we can plot and visualize it with the help of following script −

经过预测,我们可以在以下脚本的帮助下进行绘制和可视化-

Example


plt.scatter(X_test, y_test, color='red')
plt.plot(X_test, y_test_pred, color='black', linewidth=2)
plt.xticks(())
plt.yticks(())
plt.show()

Output

输出量

In the above output, we can see the regression line between the data points.

在上面的输出中,我们可以看到数据点之间的回归线。

步骤6:性能计算 (Step 6: Performance computation)

We can also compute the performance of our regression model with the help of various performance metrics as follows −

我们还可以借助各种性能指标来计算回归模型的性能,如下所示:

Example


print("Regressor model performance:")
print("Mean absolute error(MAE) =", round(sm.mean_absolute_error(y_test, y_test_pred), 2))
print("Mean squared error(MSE) =", round(sm.mean_squared_error(y_test, y_test_pred), 2))
print("Median absolute error =", round(sm.median_absolute_error(y_test, y_test_pred), 2))
print("Explain variance score =", round(sm.explained_variance_score(y_test, y_test_pred), 2))
print("R2 score =", round(sm.r2_score(y_test, y_test_pred), 2))

Output

输出量


Regressor model performance:
Mean absolute error(MAE) = 1.78
Mean squared error(MSE) = 3.89
Median absolute error = 2.01
Explain variance score = -0.09
R2 score = -0.09

ML回归算法的类型 (Types of ML Regression Algorithms)

The most useful and popular ML regression algorithm is Linear regression algorithm which further divided into two types namely −

最有用和最受欢迎的ML回归算法是线性回归算法,该算法进一步分为两种类型,即-

  • Simple Linear Regression algorithm

    简单线性回归算法

  • Multiple Linear Regression algorithm.

    多元线性回归算法。

We will discuss about it and implement it in Python in the next chapter.

我们将在下一章讨论并在Python中实现它。

应用领域 (Applications)

The applications of ML regression algorithms are as follows −

ML回归算法的应用如下-

Forecasting or Predictive analysis − One of the important uses of regression is forecasting or predictive analysis. For example, we can forecast GDP, oil prices or in simple words the quantitative data that changes with the passage of time.

预测或预测分析 -回归的重要用途之一是预测或预测分析。 例如,我们可以预测GDP,石油价格或简单地说随时间推移而变化的定量数据。

Optimization − We can optimize business processes with the help of regression. For example, a store manager can create a statistical model to understand the peek time of coming of customers.

优化 -我们可以借助回归来优化业务流程。 例如,商店经理可以创建统计模型以了解顾客来访的时间。

Error correction − In business, taking correct decision is equally important as optimizing the business process. Regression can help us to take correct decision as well in correcting the already implemented decision.

纠错 -在业务中,做出正确的决定与优化业务流程同等重要。 回归可以帮助我们做出正确的决定,也可以纠正已经实施的决定。

Economics − It is the most used tool in economics. We can use regression to predict supply, demand, consumption, inventory investment etc.

经济学 -这是经济学中最常用的工具。 我们可以使用回归来预测供应,需求,消耗,库存投资等。

Finance − A financial company is always interested in minimizing the risk portfolio and want to know the factors that affects the customers. All these can be predicted with the help of regression model.

金融 -金融公司始终对最小化风险投资组合感兴趣,并希望了解影响客户的因素。 所有这些都可以借助回归模型进行预测。

翻译自: https://www.tutorialspoint.com/machine_learning_with_python/regression_algorithms_overview.htm

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

回归算法-概述 的相关文章

  • 如何实现 __eq__ 进行集合包含测试?

    我遇到了一个问题 我将一个实例添加到一个集合中 然后进行测试以查看该对象是否存在于该集合中 我已经覆盖了 eq 但在包含测试期间不会调用它 我必须覆盖吗 hash 反而 如果是这样 我将如何实施 hash 鉴于我需要对元组 列表和字典进行哈
  • pandas Wide_to_long 后缀参数

    我对在 pandas 中使用 Wide to long 时的参数有疑问 有一个参数叫suffix我不明白 在文档中它说 后缀 str 默认 d 捕获所需后缀的正则表达式 d 捕获数字后缀 没有数字的后缀可以用否定字符类 D 指定 您还可以进
  • 使用应用程序脚本将 MS Word 文件(保存在云端硬盘中)转换为 Google 文档

    我被某些事情困住了 找不到解决办法 有没有办法使用文件 url 或 id 将存储在 Google Drive 中的 MS Word 文件转换为 Google 文档 我目前有一个电子表格 其中包含文件的网址 或者 也可以使用 python 脚
  • ca 证书 Mac OS X

    我需要在emacs 上安装offlineimap 和mu4e 问题是配置 当我运行 Offlineimap 时 我得到 OfflineIMAP 6 5 5 Licensed under the GNU GPL v2 v2 or any la
  • 组和平均 NumPy 矩阵

    假设我有一个任意的 numpy 矩阵 如下所示 arr 6 0 12 0 1 0 7 0 9 0 1 0 8 0 7 0 1 0 4 0 3 0 2 0 6 0 1 0 2 0 2 0 5 0 2 0 9 0 4 0 3 0 2 0 1 0
  • 无法使用 BeautifulSoup 和 Requests 抓取下拉菜单

    我想抓取百年灵网站上的产品页面以获取各种信息 示例页面 https www breitling com gb en watches navitimer b01 chronograph 46 AB0127211C1A1 https www b
  • Python 的 mysqldb 晦涩文档

    Python 模块 mysqldb 中有许多转义函数 我不理解它们的文档 而且我努力查找它们也没有发现任何结果 gt gt gt print mysql escape doc escape obj dict escape any speci
  • 按多个键分组并对字典列表的值进行汇总/平均值

    在Python中按多个键进行分组并对字典列表进行汇总 平均值的最Pythonic方法是什么 假设我有一个字典列表 如下所示 input dept 001 sku foo transId uniqueId1 qty 100 dept 001
  • 如何使用 PyMongo 在重复键错误后继续插入

    如果我需要在 MongoDB 中插入尚不存在的文档 db stock update one document set document upsert True 将完成这项工作 如果我错了 请随时纠正我 但是 如果我有一个文档列表并想将它们全
  • 在 Linux 上的 Python 中使用受密码保护的 Excel 工作表

    问题很简单 我每周都会收到一堆受密码保护的 Excel 文件 我必须解析它们并使用 Python 将某些部分写入新文件 我得到了文件的密码 当在 Windows 上完成此操作时 处理起来很简单 我只需导入 win32com 并使用 clie
  • pandas 中连续数据的平行坐标图

    pandas 的 parallel coordinates 函数非常有用 import pandas import matplotlib pyplot as plt from pandas tools plotting import par
  • uri 警告中缺少端口:使用 Python OpenCV cv2.VideoCapture() 打开文件时出错

    当我尝试流式传输 ipcam 时 出现了如下所示的错误 tcp 000000000048c640 uri 中缺少端口 警告 打开文件时出错 build opencv modules videoio src cap ffmpeg impl h
  • 在python中读取PASCAL VOC注释

    我在 xml 文件中有注释 例如这个 它遵循 PASCAL VOC 约定
  • Python 导入非常慢 - Anaconda python 2.7

    我的 python import 语句变得非常慢 我使用 Anaconda 包在本地运行 python 2 7 导入模块后 我编写的代码运行得非常快 似乎只是导入需要很长时间 例如 我使用以下代码运行了一个 tester py 文件 imp
  • 在 HDF5 (PyTables) 中存储 numpy 稀疏矩阵

    我在使用 PyTables 存储 numpy csr matrix 时遇到问题 我收到此错误 TypeError objects of type csr matrix are not supported in this context so
  • 沿轴 0 重复 scipy csr 稀疏矩阵

    我想重复 scipy csr 稀疏矩阵的行 但是当我尝试调用 numpy 的重复方法时 它只是将稀疏矩阵视为对象 并且只会将其作为 ndarray 中的对象重复 我浏览了文档 但找不到任何实用程序来重复 scipy csr 稀疏矩阵的行 我
  • Streamlabs API 405 响应代码

    我正在尝试使用Streamlabs API https dev streamlabs com Streamlabs API 使用 Oauth2 来创建应用程序 因此 首先我将使用我的应用程序的用户发送到一个授权链接 其中包含我的应用程序的客
  • 使用 SERVER_NAME 时出现 Flask 404

    在我的 Flask 配置中 我将 SERVER NAME 设置为 app example com 之类的域 我这样做是因为我需要使用url for with external网址 如果未设置 SERVER NAME Flask 会认为服务器
  • 在python中对列表列表执行行总和和列总和

    我想用python计算矩阵的行和和列和 但是 由于信息安全要求 我无法使用任何外部库 因此 为了创建矩阵 我使用了列表列表 如下所示 matrix 0 for x in range 5 for y in range 5 for pos in
  • Python 中的字符串slugification

    我正在寻找 slugify 字符串的最佳方法 蛞蝓 是什么 https stackoverflow com questions 427102 in django what is a slug 我当前的解决方案基于这个食谱 http code

随机推荐

  • java代码 阿里云短信 手机接受验证码

    package com antifreeze server controller import com aliyuncs DefaultAcsClient import com aliyuncs IAcsClient import com
  • AppDomain 和动态加载

    应用程序体系结构 在我专攻代码之前 我想谈谈我尝试做的事 您可能记得 SuperGraph 让您从函数列表中进行选择 我希望能够在具体的目录中放置外接程序程序集 让 SuperGraph 检测它们 加载它们 并找到它们中包含的所有函数 如果
  • DCDC电源设计中需要考虑的问题

    一 电子开关设计 1 为什么用MOS管做开关管 2 MOS驱动电路用图腾柱还是用推挽电路 3 MOS悬浮电压设计思想以及工作原理 二 PWM驱动波形 1 频率如何设置 2 占空比如何调整 3 三角波生成电路如何设计 4 比较器参考电压如何选
  • linux下的主要目录

    2019独角兽企业重金招聘Python工程师标准 gt gt gt Linux系统目录结构 登录系统后 在当前命令窗口下输入 ls 你会看到 以下是对这些目录的解释 bin bin是Binary的缩写 这个目录存放着最经常使用的命令 boo
  • 将lgbm模型进行5折交叉验证,并用GridSearchCV进行超参搜索,并打印输出每一折的精度...

    你可以使用 sklearn 的 GridSearchCV 函数来实现 lgbm 模型的 5 折交叉验证和超参数搜索 首先 需要定义模型和要调整的超参数的范围 import lightgbm as lgb from sklearn model
  • 1001 害死人不偿命的(3n+1)猜想 (15分)_Quentin

    题目链接 1001 害死人不偿命的 3n 1 猜想 15分 卡拉兹 Callatz 猜想 对任何一个正整数 n 如果它是偶数 那么把它砍掉一半 如果它是奇数 那么把 3n 1 砍掉一半 这样一直反复砍下去 最后一定在某一步得到 n 1 卡拉
  • 【翻译】知识的诅咒

    巧合的是 本周我和五组不同的人进行了同样的对话 我想我应该把我的想法写下来 并把它们写在博客上 因为这一连串的想法似乎引起了很多人的共鸣 这场对话从一个偏见开始 和我一起工作的许多人是工程师 他们后来可能已经成为高级领导或高管 但他们曾经是
  • ios 固定定位 input获取焦点,ios 滚动条滚动 fixed固定定位失效,位置偏移

    http efe baidu com blog mobile fixed layout 还发现一个问题就是ios input设置readonly 还是能看到光标 然后解决方法是在行内写了 nf cus this blur
  • Zabbix 4.0升级5.0 &&ES 6.1升级7.0

    Zabbix 4 0升级5 0 一 升级方案 1影响范围 升级期间 不会影响到现有的系统 系统将保持正常的运行 升级完成后 将进行一段时间的可用性测试 待系统稳定后将替换生产上的监控 2升级方法 本次升级采用蓝绿部署的方式 先在测试环境重新
  • com中abc.h不能修改,只能修改abc.idl,生成abc.h

    如题 犯了这个错误
  • 小笔记1:在Unity中导入模型后,材质被锁定后无法更改

    每天进步一点点小笔记 解决方案 方法1 在资源里查找到该模型 右侧inspector栏 Materials location选择Use External Material 点击Apply导入便可以编辑 方法2 在资源里查找到该模型 右侧in
  • opkg软件源设置

    opkg软件源定义在 etc opkg distfeeds conf 更新 etc opkg conf并没有什么卵用 文件中 包含软件源索引的目录路径 分为base luci management packages routeing tel
  • live555 流媒体开源库

    live555对每一个从事过流媒体开发的从业者而言 都不曾陌生 就像每一个从事音视频行业的从业者而言 ffmpeg也不曾陌生 随着行业需求的发展 live555也是越见强大 因前几天帮朋友项目查找问题 重拾live555 没想到时隔10年
  • 树莓派修改国内软件源

    编辑sources list文件 sudo nano etc apt sources list 注释掉现有的代码 新增以下代码 deb http mirrors tuna tsinghua edu cn raspbian raspbian
  • 精准营销获客如何成为企业未来的发展趋势 ,运营商大数据

    精准营销最大的优势在于 精准 即在细分市场的基础上 对不同的消费者进行详细分析 确定目标受众 精准营销的主要特点如下 1 数据范围广 可以说是全球数据 目前 中国三大运营商覆盖了数十亿互联网用户 可以说是非常全面的 可以满足各个行业的需求
  • 并发编程系列之原子操作实现原理

    前言 上节我们讲了并发编程中最基本的两个元素的底层实现 同样并发编程中还有一个很重要的元素 就是原子操作 原子本意是不可以再被分割的最小粒子 原子操作就是指不可中断的一个或者一系列操作 那么今天我们就来看看在多处理器环境下Java是如何保证
  • Kali Linux版本手动更新

    Kali Linux版本手动更新 前言 一 查看版本信息 二 更换apt源 三 apt get的使用 四 查看版本信息 总结 前言 学校这几天在上实训课 用到kali 老师推荐下载最新的版本 大家纷纷把原有的kali删了再到官网下最新版本的
  • Sentinel 原理讲解

    Blog Posts Sentinel 为 Dubbo 服务保驾护航 by Eric Zhao 在生产环境中使用 Sentinel 控制台 by Eric Zhao Sentinel 与 Hystrix 的对比 by Eric Zhao G
  • 基于51单片机的停车场车位管理系统

    具体实现功能 由AT89S52单片机 AT24C02数据存储模块 按键模块 LCD1602显示 报警模块等构成 具体功能 1 显示停车场现有车辆数和已停放过车辆数 总共16个车位 指示灯指示具体的车位占用情况 2 可以手动设置总车位数以及剩
  • 回归算法-概述

    回归算法 概述 Regression Algorithms Overview 回归概论 Introduction to Regression Regression is another important and broadly used