Week 5 Linear Models for Classification (Part A)

这篇博客探讨了线性分类的基本概念,包括回归与分类的区别、线性分类器和决策边界。深入介绍了判别模型,特别是感知器算法,讨论了多层感知机(MLP)的结构和防止过拟合的策略。内容涵盖线性模型、判别函数、生成模型和感知机算法的细节,以及在实际问题中的应用。
摘要由CSDN通过智能技术生成

目录

一、线性分类的基本概念

1、回归与分类(Regression vs Classification)

2、从线性回归到线性分类

3、分类器(Classifier)

3、决策边界(Decision Boundary)

4、线性分类器(Linear Classifier)

5、广义线性模型(Generalised Linear Models)

​二、判别模型(Discriminative Models)

1、定义

2、两类判别函数(Two Class Discriminant Function)

3、泛化到多分类问题(Generalisation to Multiclass Problems)

4、常见的判别模型

三、生成模型(Generative Models)-以统计学和Bayes作为理论基础

1、定义

2、常见的生成模型

3、生成模型与判别模型的区别与联系

四、感知器算法( Perceptron Algorithm)- 硬分类且属于判别模型

1、定义

2、感知机模型

3、感知机的损失函数

 4、感知机的算法步骤

5、感知机的算法的例子

 6、感知机一些重要性质

五、多层感知机(MLP)

1、多层感知机的结构图

2、多层感知机的算法流程

 六、分类过程中如何预防过拟合问题(Tutorial)

 1、交叉折叠验证

2、使用更多数据进行训练

3、移除一些特征值

4、早点停止训练

 5、正则化

6、Ensembling模型融合


一、线性分类的基本概念

1、回归与分类(Regression vs Classification)

(1)相同点:其实分类和回归的本质是一样的,都是对输入做出预测,其区别在于输出的类型。

(2)分类问题:分类问题的输出是离散型变量(如: +1、-1),是一种定性输出。(预测明天天气是阴、晴还是雨)

    生活中实际运用的例子:

  • 将客户分为良好信用、不良信用或灰色
  • 预测电子邮件是否为垃圾邮件,是否应发送到垃圾邮件文件夹
  • 识别手写数字图像

(3)回归问题:回归问题的输出是连续型变量,是一种定量输出。(预测明天的温度是多少度)

     生活中实际运用的例子:

  • 根据房屋面积的增加预测房价
  • 根据学习时间预测考试结果
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Sure, here's an example implementation of a linear SVM model for binary classification using PyTorch and autograd for optimization: ``` import torch import torch.nn as nn import torch.optim as optim class LinearSVM(nn.Module): def __init__(self, input_dim): super(LinearSVM, self).__init__() self.weights = nn.Parameter(torch.randn(input_dim)) self.bias = nn.Parameter(torch.randn(1)) def forward(self, x): linear_output = torch.dot(x, self.weights) + self.bias return linear_output # Define training data and labels train_data = torch.tensor([[1.0, 2.0], [2.0, 3.0], [3.0, 4.0], [4.0, 5.0]]) train_labels = torch.tensor([1, 1, -1, -1]) # Initialize model and optimizer svm = LinearSVM(input_dim=2) optimizer = optim.SGD(svm.parameters(), lr=0.01) # Define training loop num_epochs = 1000 for epoch in range(num_epochs): svm.train() optimizer.zero_grad() output = svm(train_data) loss = torch.mean(torch.clamp(1 - train_labels * output, min=0)) loss.backward() optimizer.step() # Evaluate model on test data test_data = torch.tensor([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0], [4.0, 4.0]]) svm.eval() test_predictions = torch.sign(svm(test_data)).detach().numpy() print(test_predictions) ``` In this example, we define a `LinearSVM` class that inherits from `nn.Module` and implements a linear SVM model with a single linear layer. We use `nn.Parameter` to define the model's weight and bias parameters, which are then optimized using the `optim.SGD` optimizer. In the training loop, we compute the SVM loss using the hinge loss function and backpropagate the gradients using autograd. We then update the model parameters using the optimizer's `step` method. Finally, we evaluate the trained model on some test data by passing it through the model and taking the sign of the output (since the SVM is a binary classifier). We use `detach().numpy()` to convert the output to a numpy array for easier interpretation. Note: This is just a simple example implementation of a linear SVM in PyTorch using autograd. In practice, you may want to use a more robust implementation or library for SVMs, such as LIBLINEAR or scikit-learn.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

金州饿霸

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值