• Concept in English
  • Coding Portion
  • 评估回归的性能指标——R平方指标
  • 比较分类和回归

Continuous supervised learning 连续变量监督学习

Regression 回归

Continuous:有一定次序,且可以比较大小

一、Concept in English

Slope: 斜率

Intercept: 截距

coefficient:系数

二、Coding Portion

Google: sklearn regression



import numpy
import matplotlib.pyplot as plt from ages_net_worths import ageNetWorthData ages_train, ages_test, net_worths_train, net_worths_test = ageNetWorthData() from sklearn.linear_model import LinearRegression reg = LinearRegression()
reg.fit(ages_train, net_worths_train) ### get Katie's net worth (she's 27)
### sklearn predictions are returned in an array, so you'll want to index into
### the output to get what you want, e.g. net_worth = predict([[27]])[0][0] (not
### exact syntax, the point is the [0] at the end). In addition, make sure the
### argument to your prediction function is in the expected format - if you get
### a warning about needing a 2d array for your data, a list of lists will be
### interpreted by sklearn as such (e.g. [[27]]).
km_net_worth = 1.0 ### fill in the line of code to get the right value
km_net_worth = reg.predict([[27]])[0][0]
### get the slope
### again, you'll get a 2-D array, so stick the [0][0] at the end
slope = 0. ### fill in the line of code to get the right value
slope = reg.coef_[0][0]
#print reg.coef_ ### get the intercept
### here you get a 1-D array, so stick [0] on the end to access
### the info we want
intercept = 0. ### fill in the line of code to get the right value
intercept = reg.intercept_[0] ### get the score on test data
test_score = 0. ### fill in the line of code to get the right value
test_score = reg.score(ages_test,net_worths_test) ### get the score on the training data
training_score = 0. ### fill in the line of code to get the right value
training_score = reg.score(ages_train,net_worths_train) ### print all the value
def submitFit():
# all of the values in the returned dictionary are expected to be
# numbers for the purpose of the grader.
return {"networth":km_net_worth,
"slope":slope,
"intercept":intercept,
"stats on test":test_score,
"stats on training": training_score}

三、评估回归的性能指标

评估拟合程度

3.1 最小化误差平方和

SSE sum of Squared Errors

  • 相关算法实现

1.Ordinary Least Squares(OLS,普通最小二乘法)

2.Gradient Descent (梯度下降算法)

不足: 添加的数据越多,误差平方的和必然增加,但并不代表拟合程度不好

解决方案: R平方指标

3.2 R平方指标

r平方越高,性能越好(MAX = 1)

定义: 有多少输出的改变能用输入的改变解释

优点: 与训练点的数量无关

  • Sklearn中的R平方
print "r-squared score:",reg.score(x,y)

R平方有可能小于0!

The coefficient R^2 is defined as (1 - u/v), where u is the regression sum of squares ((y_true - y_pred) ** 2).sum() and v is the residual sum of squares ((y_true - y_true.mean()) ** 2).sum(). Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a R^2 score of 0.0.

四、比较分类和回归

特性 监督分类 回归
输出类型 标签(离散) 值(连续)
寻找的结果(可视化) 决策边界 最佳拟合曲线
评判模型的标准 准确度 误差平方和or R平方指标

【Udacity】线性回归方程 Regression的更多相关文章

  1. Andrew Ng机器学习算法入门((六):多变量线性回归方程求解

    多变量线性回归 之前讨论的都是单变量的情况.例如房价与房屋面积之前的关系,但是实际上,房价除了房屋面积之外,还要房间数,楼层等因素相关.那么此时就变成了一个多变量线性回归的问题.在实际问题中,多变量的 ...

  2. 【ML】求解线性回归方程(Linear Regression)

    参考资料:openclassroom 线性回归(Linear Regression) 为了拟合10岁以下儿童年龄(x1)与身高(y)之间的关系,我们假设一个关于x的函数h(x): h(x) = Θ0+ ...

  3. MATLAB线性回归方程与非线性回归方程的相关计算

    每次比赛都需要查一下,这次直接总结到自己的博客中. 以这个为例子: 2.线性方程的相关计算 x=[1,2,3,4,5]';%参数矩阵 X=[ones(5,1),x];%产生一个5行一列的矩阵,后接x矩 ...

  4. 从损失函数优化角度:讨论“线性回归(linear regression)”与”线性分类(linear classification)“的联系与区别

    1. 主要观点 线性模型是线性回归和线性分类的基础 线性回归和线性分类模型的差异主要在于损失函数形式上,我们可以将其看做是线性模型在多维空间中“不同方向”和“不同位置”的两种表现形式 损失函数是一种优 ...

  5. 7 Types of Regression Techniques you should know!

    翻译来自:http://news.csdn.net/article_preview.html?preview=1&reload=1&arcid=2825492 摘要:本文解释了回归分析 ...

  6. 【cs229-Lecture2】Linear Regression with One Variable (Week 1)(含测试数据和源码)

    从Ⅱ到Ⅳ都在讲的是线性回归,其中第Ⅱ章讲得是简单线性回归(simple linear regression, SLR)(单变量),第Ⅲ章讲的是线代基础,第Ⅳ章讲的是多元回归(大于一个自变量). 本文的 ...

  7. 线性回归 Linear regression(3) 线性回归的概率解释

    这篇博客从一种方式推导了Linear regression 线性回归的概率解释,内容来自Standford公开课machine learning中Andrew老师的讲解. 线性回归的概率解释 在Lin ...

  8. 【机器学习实战】第9章 树回归(Tree Regression)

    第9章 树回归 <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/ ...

  9. 【机器学习实战】第8章 预测数值型数据:回归(Regression)

    第8章 预测数值型数据:回归 <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/ ...

随机推荐

  1. A: Absolutely Simple---巴什博弈

    A: Absolutely Simple 时间限制: 1 s      内存限制: 128 MB        题目描述 Ocean暑假去海边玩,海边有许多好看的贝壳.并且Ocean捡了好多回来. 回 ...

  2. 基于两阶段提交的分布式事务实现(UP-2PC)

    引言:分布式事务是分布式数据库的基础性功能,在2017年上海MySQL嘉年华(IMG)和中国数据库大会(DTCC2018)中作者都对银联UPSQL Proxy的分布式事务做了简要介绍,受限于交流形式难 ...

  3. CDH集群安装配置(二)- 公共环境的配置和虚拟机的克隆

    1. 配置网络-ip地址设置静态 vi /etc/sysconfig/network-scripts/ifcfg-eth33 增加如下配置 ONBOOT=yes BOOTPROTO=static IP ...

  4. Linux工具安装配置

    1.修改主机名/添加别名访问 修改/etc/sysconfig/network中的hostnameNETWORKING=yesHOSTNAME=dlserver01; 修改/etc/hosts文件 1 ...

  5. 《数据密集型应用系统设计》读书笔记-ch1可靠、可扩展与可维护的应用系统

    我们以Twitter为例,使用其2012年11月发布的数据.Twitter的两个典型业务操作是: - 发布tweet消息: 用户可以快速推送新消息到所有的关注者,平均大约4.6k request/se ...

  6. 查看SqlServer某张表的物理空间占用情况

    以下语句可以查看表的物理空间使用情况 包括 [ROWS] 内容的行数.. [reserved] 保留的磁盘大小.. [data] 数据占用的磁盘大小.. [index_size] 索引占用的磁盘大小. ...

  7. npm全局安装和局部文件安装区别

    全局安装往往是安装一个工具,他不是安装在一个文件夹下,而是安装在某个全局环境下,如目前我的安装路径是: C:\Users\cvter\AppData\Roaming\npm 在这里,我们可以看到所有全 ...

  8. WPF的DatePicker--日期选择器

    1. 日期选择器 DatePicker, 如图: 点击打开后显示如下: 2. 关键属性 SelectedDate SelectedDate属性, DateTime? 类型(可为空的DateTime类型 ...

  9. 游戏场景下的DDoS风险分析及防护

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 作者:腾讯游戏云资深架构师 vince 本篇文章主要是分享游戏业务面临的安全风险场景,以及基于这些场景的特点,我们应该如何做好对应的防护. ...

  10. 个人总结——Beta版本

    我们这次项目因为种种原因失败了,没办法达到预期的效果,这一点着实让人难过.但是作为一门课程,并不能说因为此次项目的失败就完全一无所获.在不断遇到困难和解决困难中学习,成长.虽然失败,但此次失败的经验教 ...