sklearn 线性模型使用入门
LinearRegression fits a linear model with coefficients
to minimize the residual sum of squares between the observed responses in the dataset, and the responses predicted by the linear approximation. Mathematically it solves a problem of the form:
原理最小化: 
>>> from sklearn import linear_model
>>> clf = linear_model.LinearRegression()
>>> clf.fit ([[, ], [, ], [, ]], [, , ])
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=, normalize=False)
>>> clf.coef_
array([ 0.5, 0.5])
完整代理例子
#!/usr/bin/env python
# coding=utf-8 import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets,linear_model print(__doc__) # load dataset
diabetes = datasets.load_diabetes() # use only one feature
diabetes_x = diabetes.data[:,np.newaxis]
diabetes_x_temp = diabetes_x[:,:,2] # split data into training/testing sets
diabetes_x_train = diabetes_x_temp[:-20]
diabetes_x_test = diabetes_x_temp[-20:] # split the targets into training/testing sets
diabetes_y_train = diabetes.target[:-20]
diabetes_y_test = diabetes.target[-20:] # create linear regression object
regr = linear_model.LinearRegression()
regr.fit(diabetes_x_train,diabetes_y_train) # the coefficients
print('coefficients: \n ',regr.coef_) # the mean square error
print("Residual sum of squares:%.2f" % np.mean((regr.predict(diabetes_x_test)-diabetes_y_test)**2)) # Plot outputs
plt.scatter(diabetes_x_test,diabetes_y_test,color='black')
plt.plot(diabetes_x_test,regr.predict(diabetes_x_test),color='blue',linewidth=3) plt.title("linear_model example")
plt.xlabel("X")
plt.ylabel("Y")
# plt.xticks(())
# plt.yticks(()) plt.show()

转自:
http://scikit-learn.org/dev/auto_examples/linear_model/plot_ols.html#example-linear-model-plot-ols-py
sklearn 线性模型使用入门的更多相关文章
- sklearn.linear_model.LinearRegresion学习
sklearn线性模型之线性回归 查看官网 https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearR ...
- Kaggle实战之二分类问题
0. 前言 1. MNIST 数据集 2. 二分类器 3. 效果评测 4. 多分类器与误差分析 5. Kaggle 实战 0. 前言 "尽管新技术新算法层出不穷,但是掌握好基础算法就能解决手 ...
- Kaggle实战分类问题2
Kaggle实战之二分类问题 0. 前言 1. MNIST 数据集 2. 二分类器 3. 效果评测 4. 多分类器与误差分析 5. Kaggle 实战 0. 前言 “尽管新技术新算法层出不穷,但是掌握 ...
- python常用库 - NumPy 和 sklearn入门
Numpy 和 scikit-learn 都是python常用的第三方库.numpy库可以用来存储和处理大型矩阵,并且在一定程度上弥补了python在运算效率上的不足,正是因为numpy的存在使得py ...
- sklearn 快速入门教程
1. 获取数据 1.1 导入sklearn数据集 sklearn中包含了大量的优质的数据集,在你学习机器学习的过程中,你可以通过使用这些数据集实现出不同的模型,从而提高你的动手实践能力,同时这个过程也 ...
- tensorflow实现线性模型和sklearn的线性模型比较
自己用tensorflow实现了linear模型,但是和sklearn提供的模型效果相比,实验结果差了很多,所以尝试了修改优化算法,正则化,损失函数和归一化,记录尝试的所有过程和自己的实验心得. im ...
- 数据挖掘入门系列教程(九)之基于sklearn的SVM使用
目录 介绍 基于SVM对MINIST数据集进行分类 使用SVM SVM分析垃圾邮件 加载数据集 分词 构建词云 构建数据集 进行训练 交叉验证 炼丹术 总结 参考 介绍 在上一篇博客:数据挖掘入门系列 ...
- sklearn机器学习算法--线性模型
线性模型 用于回归的线性模型 线性回归(普通最小二乘法) 岭回归 lasso 用于分类的线性模型 用于多分类的线性模型 1.线性回归 LinearRegression,模型简单,不同调节参数 #2.导 ...
- 机器学习入门之sklearn介绍
SKlearn简介 scikit-learn,又写作sklearn,是一个开源的基于python语言的机器学习工具包.它通过NumPy, SciPy和Matplotlib等python数值计算的库实现 ...
随机推荐
- 【重大更新】DevExpress v17.2新版亮点—Bootstrap篇(二)
用户界面套包DevExpress v17.2日前终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了Bootstrap Controls v17.2 的CardView.Charts ...
- WinRAR 0day漏洞 附利用过程
英国安全机构Mohammad Reza Espargham的漏洞实验室发现,流行压缩工具WinRAR 5.21最新版里存在一个安全漏洞,目前该漏洞还属于零日漏洞,同时官方正在全力修补该漏洞.同时报告该 ...
- 技术揭秘“QQ空间”自动转发不良信息
大家经常会看到QQ空间自动转发一些附带链接的不良信息,即便我们的QQ密码并没有被盗取.最近通过对一个QQ空间自动转发链接进行分析,发现该自动转发机制通过利用腾讯网站存在漏洞的页面,精心构造出利用代码获 ...
- SWIFT Function
Swift中的函数跟JAVA语言的函数差不多,但也有差别,SWIFT中定义函数可以指定参数的名称这也是别的语言没有的,好处就是增加了可读性.其返回值是放在未尾的,如以下定义一个加法器: func ad ...
- JMeter中各种请求格式--aduocd的博客
背景:1.在JMeter的HTTP请求的测试中,经常会使用到不同的请求格式.常用的格式如,json,form-data,x-www-form-urlencoded,multipart/form-dat ...
- Spring学习(二)--IOC
一.什么是IOC? 孤傲苍狼总结的理解: https://www.cnblogs.com/xdp-gacl/p/4249939.html 我的理解(不知道对不对哈,不对的话请各位大神指出): IOC往 ...
- Python CAN
/********************************************************************************* * Python CAN * 说明 ...
- ADC复用重映射
- [LeetCode&Python] Problem 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- 位操作Bit Operation算法题
一道让你拍案叫绝的算法题 这是一道看完答案会觉得很简单,但做之前很难想到答案的题目!!! 不信? Let us go ! 题目描述 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均 ...