Experiment 2: Logistic Regression and Newton's Method
196.41 KB
4 页
0 下载
64 浏览
0 评论
0 收藏
所属分类:
云计算&大数据 / 机器学习
| 语言 | 格式 | 评分 |
|---|---|---|
英语 | .pdf | 3 |
| 摘要 | ||
This document describes an experiment using Newton's Method to implement logistic regression for a binary classification problem. The task involves predicting college admission chances based on students' scores from two exams. The key steps include data preparation, plotting the data, applying Newton's Method to minimize the logistic regression cost function, and comparing it with the gradient descent method. The document also covers the mathematical foundations, including the hypothesis function, likelihood function, and gradient calculations. The experiment concludes with questions about the convergence values of theta, the iterative decrease of the likelihood function, and the decision boundary. | ||
| AI总结 | ||
## 文档总结
### 实验概述
本实验旨在通过牛顿法实现逻辑回归,解决一个二分类问题。实验使用了一个包含80个样本的数据集,其中40个样本为被大学录取的学生,40个样本为未被录取的学生。每个样本包含两门考试的成绩,目标是根据考试成绩预测学生是否被录取。
### 数据处理
1. **数据加载与预处理**:
- 数据集包含40个被录取学生和40个未被录取学生的考试成绩。
- 数据矩阵`x`的第二列是考试1的成绩,第三列是考试2的成绩,标签向量`y`使用1表示被录取,0表示未被录取。
- 在`x`矩阵中添加截距项`x0=1`。
2. **数据可视化**:
- 使用不同的符号(`+`和`o`)分别表示被录取和未被录取的学生,绘制数据分布图。
### 方法与理论
1. **逻辑回归**:
- 假设函数:`hθ(x) = g(θ^T x)`,其中`g`是sigmoid函数。
- 损失函数:使用对数似然函数的负值,即最小化`L(θ)`。
- 梯度:`∇θL = (1/m) Σ (hθ(x^i) - y^i) x^i`。
2. **牛顿法**:
- 优化目标:最小化损失函数`L(θ)`。
- 更新规则:`θ^(t+1) = θ^(t) - H^{-1} ∇θL`,其中`H`为Hessian矩阵。
- Hessian矩阵:`H = (1/m) Σ hθ(x^i)(1 - hθ(x^i)) x^i (x^i)^T`。
### 实验步骤
1. **实现牛顿法**:
- 初始θ设为零向量。
- 使用停止条件(损失函数变化小于阈值ε)进行迭代,通常5-15次迭代即可收敛。
2. **结果分析**:
- 收敛时的θ值。
- 损失函数随迭代减少的可视化。
- 绘制决策边界:`θ^T x = 0`,即`P(y=1|x;θ)=0.5`。
3. **概率计算**:
- 计算考试1得分为20,考试2得分为80的学生不被录取的概率。
### 比较与收获
- 比较梯度下降与牛顿法的收敛速度和效率。
- 通过实验理解牛顿法在优化中的优势。
### 总结
本实验通过牛顿法实现逻辑回归,展示了如何利用优化算法解决二分类问题。实验不仅验证了算法的有效性,还通过数据可视化和概率计算加深了对模型的理解。通过比较梯度下降和牛顿法,进一步认识了不同优化方法的特点和应用场景。 | ||
P1
P2
P3
P4
下载文档到本地,方便使用
文档评分













