`
daweibalong
  • 浏览: 45893 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类
最新评论

Machine Learning系列实验--Logistic function解决分类问题

阅读更多

 

分类问题的值是离散的,区别于之前的线性回归问题。本次采用Logistic回归来解决分类问题,实验还是参考了pennyliang的http://blog.csdn.net/pennyliang/article/details/7045372#comments
Logistic回归问题的Matchine <wbr>Learning系列实验--Logistic <wbr>function解决分类问题,写出likelihood functionMatchine <wbr>Learning系列实验--Logistic <wbr>function解决分类问题


Matchine <wbr>Learning系列实验--Logistic <wbr>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 第二版 2017

    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 ...

    understanding machine learning theory-algorithms

    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...

    Hands-On.Machine.Learning.with.Scikit-Learn.and.TensorFlow.2017

    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,...

    machine learning logistic regression

    逻辑回归虽然名字中带有“回归”二字,但它实际上是用于解决分类问题的。不同于线性回归预测连续值,逻辑回归通过Sigmoid函数将线性模型的输出转换为介于0和1之间的概率值,以此来预测事件发生的可能性。 2. **...

    Pattern Recogintion and Machine Learning

    ### 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 ...

    Hands_On_Machine_Learning_with_Scikit_Learn_and_TensorFlow book and code

    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...

    《Machine Learning》课程PPT-吴恩达07

    机器学习 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 ...

    斯坦福公开课machine learning机器学习第五周编程作业ex4

    这个作业主要关注逻辑回归(Logistic Regression)和神经网络(Neural Networks)。我们将会涉及以下几个关键知识点: 1. **逻辑回归**:逻辑回归是一种广泛应用于分类问题的统计模型。尽管名字中有“回归”,但...

    CS229_Stanford_MachineLearning_AndrewNg 整理为完整书签单一PDF

    为了处理分类问题,课程可能会涉及逻辑回归(Logistic Regression)、决策树(Decision Trees)、支持向量机(Support Vector Machines, SVM)等算法。 CS229课程还注重讲解机器学习模型背后的数学原理和理论。例如...

    Statistical-Learning-Method_Code.zip

    这两种方法都是解决简单预测问题的基础工具。 接下来是更复杂的模型,如支持向量机(Support Vector Machine, SVM),它利用最大边界原则进行分类,特别适用于小样本和高维数据。还有决策树(Decision Tree)和随机...

    Coursera Machine Learning week3

    本次知识讲解围绕Coursera上由Andrew Ng教授提供的机器学习课程的第三周内容,该周主要讲解了逻辑回归(Logistic Regression)以及如何将其应用于两个不同的数据集上。在深入理解该课程内容之前,课程团队强烈建议...

    Andrew NG的机器学习详尽笔记

    在给定的文件信息中,我们可以看到一些关于机器学习的重要知识点,这些内容是基于著名的人工智能专家Andrew NG的课程笔记。...通过这些知识点的学习和应用,可以为解决现实世界问题提供强大的支持。

    machine-learning-projects:使用知名的UCI数据集上的回归来预测葡萄酒质量

    机器学习回归项目 使用的著名UCI数据集来预测葡萄酒质量。

    神经网络实现分类matlab代码-MachineLearningIntro-AndrewNg-Coursera:MachineLearning

    神经网络实现分类matlab代码自述文件 #Intro to Machine Learning Course of 斯坦福大学 Coursera 的 Andrew Ng 硬件的评分结果在“成绩”文件夹中 ##周 01: ##周 02: ##week 03: Logistical Regression FILES ex2...

    matlab开发-lassoonlogisticrevision的常规功能

    Logistic回归是另一种常用的统计分析方法,用于分类问题。将Lasso应用于逻辑回归(Lasso Logistic Regression)可以同时实现特征选择和模型简化,降低过拟合风险。 标题中的“matlab开发-lassoonlogisticrevision的...

    AndrewNg 吴恩达机器学习笔记

    - 描述了使用机器学习解决光学字符识别问题,包括问题描述、管道(pipeline)、天花板分析(Ceiling Analysis)。 上述知识点覆盖了吴恩达机器学习课程中的核心概念和算法,包括监督学习、无监督学习、线性回归、...

    吴恩达 machine learning 第四次作业代码

    例如,第四次作业可能会涵盖逻辑回归(Logistic Regression)、梯度下降(Gradient Descent)或者正则化(Regularization)等主题,这些都是机器学习入门阶段的重要概念。 `ex4` 文件可能是包含Python代码或MATLAB...

Global site tag (gtag.js) - Google Analytics