Machine Learning - Logistic Regression

目录

一、Activation Function

Why introduce activation functions?

There are several commonly used activation functions:

二、Sigmoid:

三、Logistic Regression Model:

四、Implementation of logistic regression:

五、Decision Boundary:


一、Activation Function

        In logistic regression, the function of the activation function is to convert the output of the linear model into a probability value, so that it can represent the probability that the sample belongs to a certain category. Logistic regression is a binary classification algorithm that calculates the linear combination of input features and maps the results through an activation function to obtain a probability value between 0 and 1.

Why introduce activation functions?

        ①Converting the output of a linear model into probability values: The goal of logistic regression is to predict the probability that a sample belongs to a certain category, while the output of a linear model is a continuous real number value. By activating the function, the output of the linear model can be mapped between 0 and 1, representing the probability that the sample belongs to a certain category.
        ② Introducing non-linear relationships: The activation function introduces non-linear relationships, enabling the logistic regression model to fit non-linear data. If there is no activation function, logistic regression becomes linear regression and cannot handle non-linear classification problems.
        ③ The need for gradient calculation: The derivative of the activation function plays an important role in gradient descent algorithms. By activating the derivative of the function, the gradient of model parameters can be calculated, thereby optimizing and updating the model.

There are several commonly used activation functions:

        Sigmoid、Tanh Function、ReLU Function(Rectified Linear Unit)、Leaky ReLU、ELU Function(Exponential Linear Unit)、Softmax Function.

二、Sigmoid:

        The sigmoid function is one of the commonly used activation functions in logistic regression, which has the following characteristics that make it suitable for use in logistic regression.
        ① The output can be mapped to a probability value between 0 and 1: the output range of the sigmoid function is between 0 and 1, and the result of linear combination can be transformed into a probability value, representing the probability that the sample belongs to a certain category. This meets the classification task requirements of logistic regression.
        ② Differentiability: The sigmoid function is differentiable throughout the entire domain, which is crucial for parameter updates using optimization algorithms such as gradient descent. By taking the derivative, the gradient of the loss function on the parameters can be obtained, thereby updating the model parameters.
        ③ Having monotonicity: The sigmoid function is a monotonically increasing function, which means that as the input increases, the output also increases. This is helpful for learning and optimizing the model.
        ④ Smoothness: The sigmoid function is smooth throughout the entire domain, without any abrupt or discontinuous points. This helps to improve the stability and convergence of the model.

The complete formula is:

g(z) = \frac{1}{ 1 + exp^{-x} }

The image is as follows:

三、Logistic Regression Model:

        Logistic regression is a linear classifier (linear model) primarily used for binary classification problems. There are only two types of classification results: 1 and 0.

四、Implementation of logistic regression:

        Assuming that we determine whether a tumor is malignant or benign based on its size, we assume the following dataset:

        We assume that 1 corresponds to malignancy and 0 corresponds to benign. Then, based on linear regression, we draw a straight line in the graph, and we divide it by the midpoint 0.5 of the interval [0,1] corresponding to the y-axis.

        We can assume that when the value of the corresponding equation z = \vec{w}x + b is greater than 0.5, the corresponding tumor is benign, otherwise it is malignant. This is a situation where the dataset is relatively balanced. What if there is an outlier?

        Obviously, the results have become less reasonable, so using only linear regression to perform logistic regression is not feasible. At this point, we need to use the commonly used activation function in logistic regression:
        Firstly, we want to fix the result of y between 0 and 1, so that it is easier to determine whether the value is 0 or 1 when making discrete value predictions. So at this point, choose a function, which is the sigmoid function, which is an S-type function with a value range of (0,1), and can map a real number to the interval of (0,1), which exactly meets all the requirements.
        We can obtain the following equation by incorporating our linear regression function into the sigmoid function:

z = \vec{w}\vec{x} + b

g(z) = \frac{1}{ 1 + exp^{-x} }

f_{\vec{w},b}(\vec{x}) = g(\vec{w}*\vec{x} + b) = \frac{1}{ 1 + exp^{-(\vec{w}*\vec{x} + b)} }

        Now, we can make predictions using the above equation. Next, we will further understand what decision boundaries are.

五、Decision Boundary:

        The decision boundary of logistic regression is a hyperplane, which divides the feature space into two regions corresponding to different categories. In binary classification problems, the decision boundary can be viewed as a straight line or curve, dividing the feature space into positive and negative classes. In multi classification problems, the decision boundary can be a hyperplane or a combination of multiple hyperplanes.
        The position of the decision boundary depends on the parameters of the logistic regression model. The logistic regression model determines the optimal decision boundary by learning the relationship between features and labels in the training data. The model optimizes parameters by maximizing the likelihood function or minimizing the loss function, in order to find the optimal decision boundary.
        After using the sigmoid function, we can specify the output rules for its results as follows:

f_{\vec{w},b}(\vec{x}) >= \frac{1}{2} => y = 1

f_{\vec{w},b}(\vec{x}) < \frac{1}{2} => y = 0

        So we can easily find the corresponding linear regression equation:

f >= \frac{1}{2} => -z = -(\vec{w}\vec{x} + b ) <= 0 => z >= 0

f < \frac{1}{2} => -z = -(\vec{w}\vec{x} + b ) > 0 => z <= 0

        The straight line corresponding to its z is what we call the decision boundary:

        Of course, not all decision boundaries are linear, and there are also many nonlinear decision boundaries. We can change the shape of the decision boundaries by adding polynomials.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/767282.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

unity 多屏幕操作

想了解基础操作请移步&#xff1a;&#xff08;重点是大佬写的好&#xff0c;这里就不再赘述&#xff09; Unity 基础 之 使用 Display 简单的实现 多屏幕显示的效果_unity display-CSDN博客 在panel上也可以通过获取 Canvas&#xff0c;来达到切换多屏幕的操作&#xff0c; …

Pear-rec:一键开启多功能捕捉分享,告别繁琐操作!

Pear-rec&#xff1a;一键捕捉每一刻&#xff0c;让每一次分享变得简单高效 - 精选真开源&#xff0c;释放新价值。 概览 Pear-rec是一款采用先进的Electron框架构建&#xff0c;并以ReactJS为前端技术基础的跨平台桌面应用&#xff0c;专注于提供全方位的屏幕捕捉与媒体处理功…

【C++】类与对象(下篇)

在本篇博客中&#xff0c;作者将会讲解类与对象的最后一篇。 一.再谈构造函数 在类与对象&#xff08;上篇&#xff09;中&#xff0c;我们讲到了构造函数&#xff0c;其实构造函数就是给每个成员变量进行赋值&#xff01;&#xff01;&#xff01; 仅仅只是赋值而已&#xf…

阿里云2核4G服务器支持多少人在线?2C4G多少钱一年?

2核4G服务器支持多少人在线&#xff1f;阿里云服务器网账号下的2核4G服务器支持20人同时在线访问&#xff0c;然而应用不同、类型不同、程序效率不同实际并发数也不同&#xff0c;2核4G服务器的在线访问人数取决于多个变量因素。 阿里云2核4G服务器多少钱一年&#xff1f;2核4…

地宫取宝dfs

分析&#xff1a; 矩阵里的每一个位置都有标记&#xff0c;要求的问题是&#xff1a;有几种方法能完成这个规定。 那么&#xff0c;我们只需要计算从开始(1,1)到最后(n,m)的深度优先搜索中&#xff0c;有几个是满足要求的即为正确答案。 有个要求是&#xff0c;如果一个格子中…

Docker-镜像仓库

Docker ⛅Docker-Registry&#x1f320;分类&#x1f320;镜像仓库工作机制&#x1f320;常用的镜像仓库&#x1f320;镜像仓库命令☃️docker login☃️docker pull☃️docker push☃️docker search☃️docker logout &#x1f320;镜像命令[部分]☃️docker images☃️docke…

Git工具的详细使用

一、环境说明 [rootgit ~]# getenforce Disabled [rootgit ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)Active: inactive (d…

网络安全实训Day9

写在前面 访问控制和防火墙桌面端安全检测与防御 网络安全实训-网络安全技术 网络安全概述 访问控制 定义&#xff1a;通过定义策略和规则来限制哪些流量能经过防火墙&#xff0c;哪些流量不能通过。本质是包过滤 可以匹配的元素 IP协议版本 源区域和目的区域 源IP地址和目…

【赠书活动】Python编程 从入门到实践 第3版(图灵出品)(文末送书-进行中)

编辑推荐 适读人群 &#xff1a;本书适合对Python感兴趣的所有读者阅读。 编程入门就选蟒蛇书&#xff01; 【经典】Python入门经典&#xff0c;常居Amazon等编程类图书TOP榜 【畅销】热销全球&#xff0c;以12个语种发行&#xff0c;影响超过 250 万读者 【口碑】好评如潮…

2-dubbo源码 : 源码环境搭建

好的开始是成功的一半&#xff0c;阅读源码也是一样。 很多同学在下定决心阅读一个开源框架之后&#xff0c;就一头扎进去&#xff0c;迷失在代码“迷宫”中。此时&#xff0c;有同学意识到&#xff0c;需要一边 Debug 一边看&#xff1b;然后又有一批同学在搭建源码环境的时候…

学习C++是否有必要学习Boost库?

C作为一门强大且灵活的编程语言&#xff0c;在软件开发领域有着广泛的应用。而在C的学习过程中&#xff0c;Boost库是一个经常被提及的重要资源。那么&#xff0c;对于C的学习者而言&#xff0c;是否有必要投入精力去学习Boost库呢&#xff1f;本文将就此问题展开详尽讨论。 一…

论文:Zero-Shot Entity Linking by Reading Entity Descriptions翻译笔记(阅读实体描述、实体链接)

文章目录 论文题目&#xff1a;通过阅读实体描述实现零样本实体链接摘要1 介绍2 零点实体链接2.1 审查&#xff1a; 实体链接2.2 任务定义2.3 与其他 EL 任务的关系 3 数据集构建4 实体链接模型4.1 生成候选4.2 候选排序 5 适应目标世界6 实验6.1 基线6.2 对未知实体和新世界6.…

C++例子

#include<iostream> using namespace std;//抽象类 //抽象cpu类 class CPU { public:virtual void calcuate()0; }; //抽象显卡类 class VideoCard { public:virtual void display()0; }; //抽象内存条类 class Memory { public:virtual void storage()0;};//电脑类 clas…

【计算机网络】物理层

文章目录 第二章 物理层一、 物理层的基本概念1. 物理层接口特性 二、数据通信基础1. 典型的数据通信模型2. 数据通信相关术语3. 设计数据通信系统要考虑的3个问题4. 三种通信方式5. 串行传输&并行传输6. 同步传输&异步传输7. 码元8. 数字通信系统数据传输速率的两种表…

rpc详解rpc框架

文章目录 概述rpc的优点组件工作流程&RPC的底层原理RPC的底层原理 RPC框架rpc框架优点RPC 的实现基础RPC的应用场景RPC使用了哪些关键技术rpc 调用异常一般怎么处理rpc和http的区别为什么RPC要比HTTP更快一些Dubbo和openfeign 区别远程调用RPC框架传输协议传输速度 概述 在…

MySQL:存储过程

1. 概念 MySQL中的存储过程指的是存储在数据库中的SQL语句集合。当创建好存储过程后&#xff0c;在运行时提供所需参数&#xff0c;存储过程就可以以代码指定的方式使用参数执行并返回值。 存储过程的特点包括&#xff1a; 封装与复用&#xff1a;可以把某一业务SQL封装在存储过…

2024年三分钟教你激活CleanMyMac v4.15.1破解版下载图文激活教程

软件介绍 CleanMyMac 系列最新X测试版本&#xff0c;CleanMyMac应该是世界上最容易使用且最强大的Mac实用系统清理工具&#xff0c;CleanMyMac X是一款集所有功能于一身的先进程序卸载清理器&#xff0c;只需两个简单步骤就可以把系统里那些乱七八糟的无用文件统统清理掉&…

使用JavaScript控制<video>视频播放

系列文章目录 文章目录 系列文章目录前言 前言 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到网站&#xff0c;这篇文章男女通用&#xff0c;看懂了就去分享给你的码吧。 HTML 元素 用于在 …

每日一题 --- 移除链表元素[力扣][Go]

移除链表元素 题目&#xff1a;203. 移除链表元素 给你一个链表的头节点 head 和一个整数 val &#xff0c;请你删除链表中所有满足 Node.val val 的节点&#xff0c;并返回 新的头节点 。 示例 1&#xff1a; 输入&#xff1a;head [1,2,6,3,4,5,6], val 6 输出&#xf…

Java——抽象类和接口

目录 1.抽象类 1.概念: 2.语法 3.特性 2.接口 1.概念 2.语法 3.特性 1.抽象类 1.概念: 在面向对象的概念中&#xff0c;所有的对象都是通过类来描绘的&#xff0c;但是反过来&#xff0c;并不是所有的类都是用来描绘对象的&#xff0c;如果一个类中没有包含足够的…