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. centos7 docker安装

    Docker分为社区版CE和企业版EE. 社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如经过官方测试认证过的基础设施.容器.插件等 社区版按照stable和edge两种 ...

  2. matplotlib使用

    import numpy as np import matplotlib.pyplot as plt 生成数据 mean1=[5,5] cov1=[[1,1],[1,1.5]] data=np.ran ...

  3. JSON数组形式字符串转换为List<Map<String,String>>的8种方法

    package com.zkn.newlearn.json; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArr ...

  4. 清北学堂part2

    今天的内容分为两部分,能听懂的和听不懂的... 整一整当前阶段(oi)非常重要的知识点,扩展欧几里得, 其他的不是不重要,只是代码实现效果不很好 代码: #include<bits/stdc++ ...

  5. POJ 3974 Palindrome (算竞进阶习题)

    hash + 二分答案 数据范围肯定不能暴力,所以考虑哈希. 把前缀和后缀都哈希过之后,扫描一边字符串,对每个字符串二分枚举回文串长度,注意要分奇数和偶数 #include <iostream& ...

  6. python 实现聊天室

    所用模块 asyncore 官方介绍, 源码 英文捉鸡点 这里  源码中可以看到其实本质上就对 select 以及 socket 的进一步封装 简单说明 Python的asyncore模块提供了以异步 ...

  7. 小程序运行报错:errMsg: "request:fail url not in domain list"

    错误原因: 报错提示说请求的url不在域名列表里,应该是还没有配置服务器域名 解决方法: 可点击开发者工具右上角 详情-项目设置-不校验合法域名.web-view(业务域名).TLS 版本以及 HTT ...

  8. java 11 完全支持Linux容器(包括Docker)

    许多运行在Java虚拟机中的应用程序(包括Apache Spark和Kafka等数据服务以及传统的企业应用程序)都可以在Docker容器中运行.但是在Docker容器中运行Java应用程序一直存在一个 ...

  9. 主席树[可持久化线段树](hdu 2665 Kth number、SP 10628 Count on a tree、ZOJ 2112 Dynamic Rankings、codeforces 813E Army Creation、codeforces960F:Pathwalks )

    在今天三黑(恶意评分刷上去的那种)两紫的智推中,突然出现了P3834 [模板]可持久化线段树 1(主席树)就突然有了不详的预感2333 果然...然后我gg了!被大佬虐了! hdu 2665 Kth ...

  10. 深度学习中Embedding的理解

    这学期为数不多的精读论文中基本上都涉及到了Embedding这个概念,下面结合自己的理解和查阅的资料对这个概念进行一下梳理. ===================================== ...