热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

机器学习、数据挖掘和统计模式识别学习(Matlab代码实现)

    目录💥

       目录

💥1 概述

📚2 运行结果

🎉3 参考文献

👨‍💻4 Matlab代码



💥1 概述

机器学习是让计算机在没有明确编程的情况下采取行动的科学。在过去的十年中,机器学习为我们提供了自动驾驶汽车,实用的语音识别,有效的网络搜索以及对人类基因组的理解大大提高。机器学习在今天是如此普遍,以至于你可能每天使用它几十次而不自知。许多研究人员还认为,这是朝着人类水平的人工智能取得进展的最佳方式。在本代码中,您将了解最有效的机器学习技术,并获得实施它们并让它们为自己工作的练习。更重要的是,您不仅将学习学习的理论基础,还将获得快速有效地将这些技术应用于新问题所需的实践知识。最后,您将了解硅谷在创新方面的一些最佳实践,因为它与机器学习和人工智能有关。本代码广泛介绍了机器学习、数据挖掘和统计模式识别。主题包括:(i)监督学习(参数/非参数算法,支持向量机,内核,神经网络)。(ii)无监督学习(聚类、降维、推荐系统、深度学习)。(iii)机器学习的最佳实践(偏差/方差理论;机器学习和人工智能的创新过程)。本课程还将借鉴众多案例研究和应用,以便您还将学习如何应用学习算法来构建智能机器人(感知、控制)、文本理解(网络搜索、反垃圾邮件)、计算机视觉、医学信息学、音频、数据库挖掘和其他领域。

📚2 运行结果

主函数部分代码:

%% Machine Learning Online Class

%  Exercise 6 | Spam Classification with SVMs

%

%  Instructions

%  ------------

%  This file contains code that helps you get started on the

%  exercise. You will need to complete the following functions:

%

%     gaussianKernel.m

%     dataset3Params.m

%     processEmail.m

%     emailFeatures.m

%

%  For this exercise, you will not need to change any code in this file,

%  or any other files other than those mentioned above.

%

%% Initialization

clear ; close all; clc

%% ==================== Part 1: Email Preprocessing ====================

%  To use an SVM to classify emails into Spam v.s. Non-Spam, you first need

%  to convert each email into a vector of features. In this part, you will

%  implement the preprocessing steps for each email. You should

%  complete the code in processEmail.m to produce a word indices vector

%  for a given email.

fprintf('\nPreprocessing sample email (emailSample1.txt)\n');

% Extract Features

file_contents = readFile('emailSample1.txt');

word_indices  = processEmail(file_contents);

% Print Stats

fprintf('Word Indices: \n');

fprintf(' %d', word_indices);

fprintf('\n\n');

fprintf('Program paused. Press enter to continue.\n');

pause;

%% ==================== Part 2: Feature Extraction ====================

%  Now, you will convert each email into a vector of features in R^n. 

%  You should complete the code in emailFeatures.m to produce a feature

%  vector for a given email.

fprintf('\nExtracting features from sample email (emailSample1.txt)\n');

% Extract Features

file_contents = readFile('emailSample1.txt');

word_indices  = processEmail(file_contents);

features      = emailFeatures(word_indices);

% Print Stats

fprintf('Length of feature vector: %d\n', length(features));

fprintf('Number of non-zero entries: %d\n', sum(features > 0));

fprintf('Program paused. Press enter to continue.\n');

pause;

%% =========== Part 3: Train Linear SVM for Spam Classification ========

%  In this section, you will train a linear classifier to determine if an

%  email is Spam or Not-Spam.

% Load the Spam Email dataset

% You will have X, y in your environment

load('spamTrain.mat');

fprintf('\nTraining Linear SVM (Spam Classification)\n')

fprintf('(this may take 1 to 2 minutes) ...\n')

C = 0.1;

model = svmTrain(X, y, C, @linearKernel);

p = svmPredict(model, X);

fprintf('Training Accuracy: %f\n', mean(double(p == y)) * 100);

%% =================== Part 4: Test Spam Classification ================

%  After training the classifier, we can evaluate it on a test set. We have

%  included a test set in spamTest.mat

% Load the test dataset

% You will have Xtest, ytest in your environment

load('spamTest.mat');

fprintf('\nEvaluating the trained Linear SVM on a test set ...\n')

p = svmPredict(model, Xtest);

fprintf('Test Accuracy: %f\n', mean(double(p == ytest)) * 100);

pause;

%% ================= Part 5: Top Predictors of Spam ====================

%  Since the model we are training is a linear SVM, we can inspect the

%  weights learned by the model to understand better how it is determining

%  whether an email is spam or not. The following code finds the words with

%  the highest weights in the classifier. Informally, the classifier

%  'thinks' that these words are the most likely indicators of spam.

%

% Sort the weights and obtin the vocabulary list

[weight, idx] = sort(model.w, 'descend');

vocabList = getVocabList();

fprintf('\nTop predictors of spam: \n');

for i = 1:15

    fprintf(' %-15s (%f) \n', vocabList{idx(i)}, weight(i));

end

fprintf('\n\n');

fprintf('\nProgram paused. Press enter to continue.\n');

pause;

%% =================== Part 6: Try Your Own Emails =====================

%  Now that you've trained the spam classifier, you can use it on your own

%  emails! In the starter code, we have included spamSample1.txt,

%  spamSample2.txt, emailSample1.txt and emailSample2.txt as examples. 

%  The following code reads in one of these emails and then uses your 

%  learned SVM classifier to determine whether the email is Spam or 

%  Not Spam

% Set the file to be read in (change this to spamSample2.txt,

% emailSample1.txt or emailSample2.txt to see different predictions on

% different emails types). Try your own emails as well!

filename = 'spamSample1.txt';

% Read and predict

file_contents = readFile(filename);

word_indices  = processEmail(file_contents);

x             = emailFeatures(word_indices);

p = svmPredict(model, x);

fprintf('\nProcessed %s\n\nSpam Classification: %d\n', filename, p);

fprintf('(1 indicates spam, 0 indicates not spam)\n\n');


🎉3 参考文献

​[1]谢宜鑫. 基于机器学习的建筑空调能耗数据挖掘和模式识别[D].北京交通大学,2019.

👨‍💻4 Matlab代码



推荐阅读
  • 毕业设计:基于机器学习与深度学习的垃圾邮件(短信)分类算法实现
    本文详细介绍了如何使用机器学习和深度学习技术对垃圾邮件和短信进行分类。内容涵盖从数据集介绍、预处理、特征提取到模型训练与评估的完整流程,并提供了具体的代码示例和实验结果。 ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • 本文探讨了如何在给定整数N的情况下,找到两个不同的整数a和b,使得它们的和最大,并且满足特定的数学条件。 ... [详细]
  • 机器学习中的相似度度量与模型优化
    本文探讨了机器学习中常见的相似度度量方法,包括余弦相似度、欧氏距离和马氏距离,并详细介绍了如何通过选择合适的模型复杂度和正则化来提高模型的泛化能力。此外,文章还涵盖了模型评估的各种方法和指标,以及不同分类器的工作原理和应用场景。 ... [详细]
  •   上一篇博客中我们说到线性回归和逻辑回归之间隐隐约约好像有什么关系,到底是什么关系呢?我们就来探讨一下吧。(这一篇数学推导占了大多数,可能看起来会略有枯燥,但这本身就是一个把之前算法 ... [详细]
  • Coursera ML 机器学习
    2019独角兽企业重金招聘Python工程师标准线性回归算法计算过程CostFunction梯度下降算法多变量回归![选择特征](https:static.oschina.n ... [详细]
  • 本文旨在探讨如何利用决策树算法实现对男女性别的分类。通过引入信息熵和信息增益的概念,结合具体的数据集,详细介绍了决策树的构建过程,并展示了其在实际应用中的效果。 ... [详细]
  • 本文深入探讨了CART(分类与回归树)的基本原理及其在随机森林中的应用。重点介绍了CART的分裂准则、防止过拟合的方法、处理样本不平衡的策略以及其在回归问题中的应用。此外,还详细解释了随机森林的构建过程、样本均衡处理、OOB估计及特征重要性的计算。 ... [详细]
  • 京东AI创新之路:周伯文解析京东AI战略的独特之处
    2018年4月15日,京东在北京举办了人工智能创新峰会,会上首次公开了京东AI的整体布局和发展方向。此次峰会不仅展示了京东在AI领域的最新成果,还标志着京东AI团队的首次集体亮相。本文将深入探讨京东AI的发展策略及其与BAT等公司的不同之处。 ... [详细]
  • 《计算机视觉:算法与应用》第二版初稿上线,全面更新迎接未来
    经典计算机视觉教材《计算机视觉:算法与应用》迎来了其第二版,现已开放初稿下载。本书由Facebook研究科学家Richard Szeliski撰写,自2010年首版以来,一直是该领域的标准参考书。 ... [详细]
  • 探索CNN的可视化技术
    神经网络的可视化在理论学习与实践应用中扮演着至关重要的角色。本文深入探讨了三种有效的CNN(卷积神经网络)可视化方法,旨在帮助读者更好地理解和优化模型。 ... [详细]
  • 深入解析Android自定义View面试题
    本文探讨了Android Launcher开发中自定义View的重要性,并通过一道经典的面试题,帮助开发者更好地理解自定义View的实现细节。文章不仅涵盖了基础知识,还提供了实际操作建议。 ... [详细]
  • 本文详细介绍了Java编程语言中的核心概念和常见面试问题,包括集合类、数据结构、线程处理、Java虚拟机(JVM)、HTTP协议以及Git操作等方面的内容。通过深入分析每个主题,帮助读者更好地理解Java的关键特性和最佳实践。 ... [详细]
  • 2017年人工智能领域的十大里程碑事件回顾
    随着2018年的临近,我们一同回顾过去一年中人工智能领域的重要进展。这一年,无论是政策层面的支持,还是技术上的突破,都显示了人工智能发展的迅猛势头。以下是精选的2017年人工智能领域最具影响力的事件。 ... [详细]
  • 智慧城市建设现状及未来趋势
    随着新基建政策的推进及‘十四五’规划的实施,我国正步入以5G、人工智能等先进技术引领的智慧经济新时代。规划强调加速数字化转型,促进数字政府建设,新基建政策亦倡导城市基础设施的全面数字化。本文探讨了智慧城市的发展背景、全球及国内进展、市场规模、架构设计,以及百度、阿里、腾讯、华为等领军企业在该领域的布局策略。 ... [详细]
author-avatar
海滨的微博小窝
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有