sklearn实践_普通线性回归
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data = pd.read_csv(r"C:\Users\Oscar\Downloads\Advertising.csv") x = data[["TV","Radio","Newspaper"]]
y=data["Sales"]
plt.plot(data["TV"],y,"ro",Label="TV")
plt.plot(data["Radio"],y,"g^",Label="Radio")
plt.plot(data["Newspaper"],y,"bo",Label="Newspaper")
plt.legend(loc="lower right")
plt.grid()
plt.show plt.figure(figsize=(10,10)) plt.subplot(311)
plt.plot(data["TV"],y,"ro",Label="TV")
plt.title("TV") plt.subplot(312)#plt.subplot(3,1,2)
plt.plot(data["Newspaper"],y,"g^",Label="Newspaper")
plt.title("Newspaper") plt.subplot(313)
plt.plot(data["Radio"],y,"bo",Label="Radio")
plt.title("Radio") #建模
feature_cols = ["TV","Radio","Newspaper"]
X = data[feature_cols]
y = data["Sales"]
from sklearn.cross_validation import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y)
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train,y_train)
print(model)
print(model.coef_)
print(model.intercept_)
y_rep = model.predict(X_test) #评估
from sklearn import metrics
import numpy as np
sum_mean = 0
for i in range(len(y_rep)):
sum_mean+=(y_rep[i]-y_test.values[i])**2
print("RMSE:",np.sqrt(sum_mean/len(y_rep))) #作图
plt.figure()
plt.plot(range(len(y_rep)),y_rep,"b",Label="pre")
plt.plot(range(len(y_rep)),y_test,"r",Label="test")
plt.legend(loc="upper right")
plt.xlabel("the number of sales")
plt.ylabel("values of sales")
sklearn实践_普通线性回归的更多相关文章
- memcached vs MySQL Memory engine table 速度比较_XMPP Jabber即时通讯开发实践_百度空间
memcached vs MySQL Memory engine table 速度比较_XMPP Jabber即时通讯开发实践_百度空间 memcached vs MySQL Memory engin ...
- 提高mysql memory(heap) engine内存性能的开源补丁_XMPP Jabber即时通讯开发实践_百度空间
提高mysql memory(heap) engine内存性能的开源补丁_XMPP Jabber即时通讯开发实践_百度空间 提高mysql memory(heap) engine内存性能的开源补丁
- Python数模笔记-Sklearn(4)线性回归
1.什么是线性回归? 回归分析(Regression analysis)是一种统计分析方法,研究自变量和因变量之间的定量关系.回归分析不仅包括建立数学模型并估计模型参数,检验数学模型的可信度,也包括利 ...
- 使用sklearn机器学习库实现线性回归
import numpy as np # 导入科学技术框架import matplotlib.pyplot as plt # 导入画图工具from sklearn.linear_model imp ...
- 深入浅出深度学习:原理剖析与python实践_黄安埠(著) pdf
深入浅出深度学习:原理剖析与python实践 目录: 第1 部分 概要 1 1 绪论 2 1.1 人工智能.机器学习与深度学习的关系 3 1.1.1 人工智能——机器推理 4 1.1.2 机器学习—— ...
- sklearn机器学习实战-简单线性回归
记录下学习使用sklearn,将使用sklearn实现机器学习大部分内容 基于scikit-learn机器学习(第2版)这本书,和scikit-learn中文社区 简单线性回归 首先,最简单的线性回归 ...
- 【2017集美大学1412软工实践_助教博客】团队作业10——项目复审与事后分析(Beta版本)
写在前面的话 转眼轰轰烈烈本学期的软工实践就结束了,这个过程中想必在熬夜敲代码,激烈讨论中留下诸多回忆的同时,也收获了不少.恭喜所有团队完成了本阶段冲刺,此外,由于大家的贡献分给的都很平均,将个人贡献 ...
- 决策树decision tree原理介绍_python sklearn建模_乳腺癌细胞分类器(推荐AAA)
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...
- 机器学习之支持向量机原理和sklearn实践
1. 场景描述 问题:如何对对下图的线性可分数据集和线性不可分数据集进行分类? 思路: (1)对线性可分数据集找到最优分割超平面 (2)将线性不可分数据集通过某种方法转换为线性可分数据集 下面将带着这 ...
随机推荐
- 谷歌机器学习速成课程---2深入了解机器学习(Descending into ML)
1.线性回归 人们早就知晓,相比凉爽的天气,蟋蟀在较为炎热的天气里鸣叫更为频繁.数十年来,专业和业余昆虫学者已将每分钟的鸣叫声和温度方面的数据编入目录.Ruth 阿姨将她喜爱的蟋蟀数据库作为生日礼物送 ...
- 用C#编写猜数、九九乘法表‘、迷宫
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- 【leetcode刷提笔记】Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- Linux串口编程(中断方式和select方式)
Linux下的串口编程,在嵌入式开发中占据着重要的地位,因为很多的嵌入式设备都是通过串口交换数据的.在没有操作系统的我们可以使用UART的中断来出来数据的接受和发送,而在Linux操作系统下,我们也可 ...
- 嵌入式C函数优化
0. 引言 这是一个简单函数的优化,但却体现了代码易读性和效率的综合考虑. 如果问我如何写出优秀的代码,答曰:再写一版. 1. 版本1 从环形buffer中取出数据,然后放到一个结构体中.buffer ...
- Windos Server Tomcat 双开配置
Tomcat 双开配置 tomcat_1 server.mxl文件 # 修改端口 <Connector port=" protocol="HTTP/1.1" c ...
- redis 第二篇 系统命令简介 上
一.系统级命令(不归属任何一个数据结构) 从keys命令说起 1. 可以模式匹配 也就是可以用正则表达式的方式来匹配 格式为KEYS pattern glob风格通配符规则 ? 匹配一个字符 ...
- linux下安装eclipse并使用xstart远程使用(centos7)
1 eclipse安装 1)到官网下载eclipse的linux版 http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-deve ...
- numpy中的matrix与array的区别
Numpy matrices必须是2维的,但是 numpy arrays (ndarrays) 可以是多维的(1D,2D,3D····ND). Matrix是Array的一个小的分支,包含于Array ...
- R树的相关知识
转自:http://blog.csdn.net/houzuoxin/article/details/16113895 R树在数据库等领域做出的功绩是非常显著的.它很好的解决了在高维空间搜索等问题.举个 ...