Logistic回归问题的,写出likelihood function
,目标是使得l()最大化。可采用梯度上升方法进行迭代,但不同的是求最大值。
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
double h(double* x,double* q)
{
double temp = q[0] * x[0] + q[1] * x[1] + q[2] * x[2] + q[3] * x[3];
double e = pow(2.718281828, temp);
return e / (e + 1);
}
void classifier(double* pre)
{
double x[6][4]={{1,47,76,24},
{1,46,77,23},
{1,48,74,22},
{1,34,76,21},
{1,35,75,24},
{1,34,77,25},
};
double y[]={1,1,1,0,0,0};
double theta[]={1,1,1,1};
int i, j, k;
double l;
for (i = 0; i < 10000; i++)
{
for (j=0; j<4; j++)
{
double sum=0;
for (k = 0; k < 6; k++)
{
sum += (y[k] - h(x[k], theta)) * x[k][j];
}
theta[j] += 0.001 * sum;
cout << theta[j] << " ";
}
cout << endl;
l = 0;
for (j = 0; j < 6; j++)
{
l += y[j] * log(h(x[j], theta)) + (1 - y[j]) * log(1 - h(x[j], theta));
}
//cout<< l << endl;
}
cout << i << endl;
cout << h(pre, theta) << endl;
cout << l << endl;
}
int main(void)
{
double pre[] = {1, 48 ,74, 22};
classifier(pre);
return 0;
}
试验中选择了一个学习样本进行测试,得到的h(x)=0.999984, 相似的极高,若填入的测试数据为其他,可根据h(x)值的大小进行判断y值是0还是1.
分享到:
相关推荐
Mastering Machine Learning with scikit-learn (2 ed) (True PDF + AWZ3 + codes) Table of Contents Preface 1 Chapter 1: The Fundamentals of Machine Learning 6 Defining machine learning 6 Learning from ...
1.2 When Do We Need Machine Learning? 21 1.3 Types of Learning 22 1.4 Relations to Other Fields 24 1.5 How to Read This Book 25 1.5.1 Possible Course Plans Based on This Book 26 1.6 Notation 27 Part I...
The most common learning algorithms: Linear and Polynomial Regression, Logistic Regression, k-Nearest Neighbors, Support Vector Machines, Decision Trees, Random Forests, and Ensemble methods. Part II,...
逻辑回归虽然名字中带有“回归”二字,但它实际上是用于解决分类问题的。不同于线性回归预测连续值,逻辑回归通过Sigmoid函数将线性模型的输出转换为介于0和1之间的概率值,以此来预测事件发生的可能性。 2. **...
### Pattern Recognition and Machine Learning **Pattern Recognition and Machine Learning**, authored by Christopher M. Bishop, is a comprehensive textbook that covers a broad range of topics in the ...
### Pattern Recognition and Machine Learning **Pattern Recognition and Machine Learning**, authored by Christopher M. Bishop and published under the Information Science and Statistics series, is a ...
What is Machine Learning? What problems does it try to solve? What are the main categories and fundamental concepts of Machine Learning systems? • The main steps in a typical Machine Learning project...
机器学习 Regularization 1、The problem of overfitting 2、Cost function 3、Regularized linear regression 4、Regularized logistic regression
-- Kernel Logistic Regression [核型羅吉斯迴歸] -- Support Vector Regression [支持向量迴歸] Combining Predictive Features [融合預測性的特徵] -- Bootstrap Aggregation [自助聚合法] -- Adaptive Boosting ...
这个作业主要关注逻辑回归(Logistic Regression)和神经网络(Neural Networks)。我们将会涉及以下几个关键知识点: 1. **逻辑回归**:逻辑回归是一种广泛应用于分类问题的统计模型。尽管名字中有“回归”,但...
为了处理分类问题,课程可能会涉及逻辑回归(Logistic Regression)、决策树(Decision Trees)、支持向量机(Support Vector Machines, SVM)等算法。 CS229课程还注重讲解机器学习模型背后的数学原理和理论。例如...
这两种方法都是解决简单预测问题的基础工具。 接下来是更复杂的模型,如支持向量机(Support Vector Machine, SVM),它利用最大边界原则进行分类,特别适用于小样本和高维数据。还有决策树(Decision Tree)和随机...
在给定的文件信息中,我们可以看到一些关于机器学习的重要知识点,这些内容是基于著名的人工智能专家Andrew NG的课程笔记。...通过这些知识点的学习和应用,可以为解决现实世界问题提供强大的支持。
机器学习回归项目 使用的著名UCI数据集来预测葡萄酒质量。
神经网络实现分类matlab代码自述文件 #Intro to Machine Learning Course of 斯坦福大学 Coursera 的 Andrew Ng 硬件的评分结果在“成绩”文件夹中 ##周 01: ##周 02: ##week 03: Logistical Regression FILES ex2...
隐马尔可夫模型(Hidden Markov Model, HMM)是另一种利用贝叶斯推理解决序列数据分析问题的模型。HMM假设系统状态是未知的(即“隐”状态),状态的演变遵循马尔可夫链过程。HMM被广泛应用于语音识别、自然语言处理...
Logistic回归是另一种常用的统计分析方法,用于分类问题。将Lasso应用于逻辑回归(Lasso Logistic Regression)可以同时实现特征选择和模型简化,降低过拟合风险。 标题中的“matlab开发-lassoonlogisticrevision的...