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. hdu-1052(贪心)

    链接 [https://vjudge.net/contest/261555#problem/I] 题意 就是两个人都有n匹马,每只马都有战力 第二个人出马的顺序是战力大到小,请问第一个人采取怎样的策略 ...

  2. 让linux启动更快的方法

    导读 进行 Linux 内核与固件开发的时候,往往需要多次的重启,会浪费大把的时间. 在所有我拥有或使用过的电脑中,启动最快的那台是 20 世纪 80 年代的电脑.在你把手从电源键移到键盘上的时候,B ...

  3. Binary Search(Java)(非递归)

    public static int rank(int[] array, int k) { int front = 0, rear = array.length - 1; while(front < ...

  4. mybatis 使用接口绑定

    使用selectList,selectOne..的缺陷 刚开始学习mybatis的时候,使用selectList或者selectOne,传入要调用的mapper,如果又参数要传递的话,就需要将参数进行 ...

  5. poj-2516(最小费用流)

    题意:有n个商店,每个商店有k种货物,每个货物需要a[n][k]个,有m个仓库,每个仓库也有k种货物,每个货物有b[m][k]个,然后k个矩阵,每个矩阵都是n*m的,第i行第j列表示从仓库j到商店i每 ...

  6. 四、Java多人博客系统-2.0版本

    由于时间关系,多人博客系统这里穿插一个2.0版本. 2.0版本本来是打算用于建立个人网站,但是后来发现个人建站需要购买域名服务器,还需要备案,很繁琐.最终放弃.完成此版本,最终也只是作为技术演练.此版 ...

  7. 【XSY2843】「地底蔷薇」 NTT什么的 扩展拉格朗日反演

    题目大意 给定集合\(S\),请你求出\(n\)个点的"所有极大点双连通分量的大小都在\(S\)内"的不同简单无向连通图的个数对\(998244353\)取模的结果. \(n\le ...

  8. golang 笔记

    golang 的坑 package main import ( "fmt" "net/http" "time" ) func Hello(w ...

  9. create-react-app中添加less支持

    前言 使用 create-react-app 脚手架创建项目后,默认是不支持 less 的.所以我们需要手动添加. 第一步 暴露webpack配置文件 使用 create-react-app 创建的项 ...

  10. 团体程序设计天梯赛(CCCC) L3015 球队“食物链” 状态压缩

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code #include <cstdio> #include ...