sklearn线性模型之线性回归

查看官网 https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html

1.实例化:

a=LinearRegression()

参数默认:
fit_intercept=True, normalize=False, copy_X=True, n_jobs=None
fit_intercept:是否存在截距,默认存在
normalize:标准化开关,默认关闭
copy_X
n_jobs

2.方法:

#输入数据,输入x,y数据,其中参sample_weight数是指每条测试数据的权重,以array形式传入
fit(X, y[, sample_weight])    Fit linear model.
# get_params([deep]) Get parameters for this estimator. #模型预测
predict(X) Predict using the linear model #计算评分
score(X, y[, sample_weight]) Returns the coefficient of determination R^2 of the prediction.

Returns the coefficient of determination R^2 of the prediction.

The coefficient R^2 is defined as (1 - u/v), where u is the residual sum of squares ((y_true - y_pred) ** 2).sum() and v is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The 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.


作用:返回该次预测的系数R2    


其中R=(1-u/v)。


u=((y_true - y_pred) ** 2).sum()     v=((y_true - y_true.mean()) ** 2).sum()

其中可能得到的最好的分数是1,并且可能是负值(因为模型可能会变得更加糟糕)。当一个模型不论输入何种特征值,其总是输出期望的y的时候,此时返回0。



set_params(**params) Set the parameters of this estimator.

3.回归系数与截距

#回归系数
coef_
#截距
intercept_

sklearn.linear_model.LinearRegresion学习的更多相关文章

  1. Python机器学习笔记:sklearn库的学习

    网上有很多关于sklearn的学习教程,大部分都是简单的讲清楚某一方面,其实最好的教程就是官方文档. 官方文档地址:https://scikit-learn.org/stable/ (可是官方文档非常 ...

  2. sklearn.linear_model.LinearRegression

    官网:http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html class ...

  3. 使用sklearn进行集成学习——实践

    系列 <使用sklearn进行集成学习——理论> <使用sklearn进行集成学习——实践> 目录 1 Random Forest和Gradient Tree Boosting ...

  4. 使用sklearn进行集成学习——理论

    系列 <使用sklearn进行集成学习——理论> <使用sklearn进行集成学习——实践> 目录 1 前言2 集成学习是什么?3 偏差和方差 3.1 模型的偏差和方差是什么? ...

  5. [转]使用sklearn进行集成学习——理论

    转:http://www.cnblogs.com/jasonfreak/p/5657196.html 目录 1 前言2 集成学习是什么?3 偏差和方差 3.1 模型的偏差和方差是什么? 3.2 bag ...

  6. [转]使用sklearn进行集成学习——实践

    转:http://www.cnblogs.com/jasonfreak/p/5720137.html 目录 1 Random Forest和Gradient Tree Boosting参数详解2 如何 ...

  7. sklearn.linear_model.LogisticRegression参数说明

    目录 sklearn.linear_model.LogisticRegression sklearn.linear_model.LogisticRegressionCV sklearn.linear_ ...

  8. sklearn linear_model,svm,tree,naive bayes,ensemble

    sklearn linear_model,svm,tree,naive bayes,ensemble by iris dataset .caret, .dropup > .btn > .c ...

  9. sklearn datasets模块学习

    sklearn.datasets模块主要提供了一些导入.在线下载及本地生成数据集的方法,可以通过dir或help命令查看,我们会发现主要有三种形式:load_<dataset_name>. ...

随机推荐

  1. Mac之日常操作

    1.创建root用户使用最高权限 sudo passwd root 一般情况下,使用临时获取最高权限 sudo vim /etc/shells 2. apache操作 #启动Apache sudo a ...

  2. 妙解Servlet四大域对象

    pageContext pageContext作用域为page(页面执行期). request request是表示一个请求,只要发出一个请求就会创建一个request,它的作用域仅在当前请求中有效. ...

  3. vue.js实战——$event

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Django初印象之视图(view)

    一.view的初印象 一个视图函数(类),简称视图.我们发起web请求时,返回的web响应.[大家约定成俗将视图放置在项目(project)或应用程序(app)目录中的名为views.py的文件中.] ...

  5. json内存级非关系数据库

    介绍 `jsonDB2`是一个基于内存的键值对数据库(非关系型数据库) 开发初衷:实现个人tornado项目中内存session存储功能(不想引入redis等非关系型数据库) 项目地址: https: ...

  6. ☆ [ZJOI2006] 书架 「平衡树维护数列」

    题目类型:平衡树 传送门:>Here< 题意:要求维护一个数列,支持:将某个元素置顶或置底,交换某元素与其前驱或后继的位置,查询编号为\(S\)的元素的排名,查询排名第\(k\)的元素编号 ...

  7. 随手记一个漂亮的code

    代码  从前有个代码长这样 if (a) { if (b) { c } } else { if (d) { c } } 后来长这样 if (a && b || !a && ...

  8. Cucumber使用中问题

    1.cucumber自动化执行提示chrome使用不支持的命令标记 --ignore-certificate-errors 大概问题是chrome版本和chrmedriver版本不对应 2." ...

  9. Springboot 1.简介 及第一个demo

    按照官网上的新建一个maven项目,然后将类引入pom.xml文件中 <?xml version="1.0" encoding="UTF-8"?> ...

  10. 测试框架httpclent 1.HttpClient简介及第一个demo

    httpclient就是一个模拟 发送http请求的一个工具. 首先在pom.xml文件里面添加工具类 <dependencies> <dependency> <grou ...