Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1750438
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: 大数据

2020-03-27 10:09:11

这一段时间比较闲,找了UDEMY上面的教程看,看了些DataScience. 记录一下,今天是Linear Regression. 按照Lazyprogrammer的教程上,我们应该把这些所谓的DataScience都当做 Geometry.

代码如下,需要提前安装statsmodel,seaborn,pandas,matplotlib 可以使用ipython3或者jupyter.
csv文件是我从github上找的,乱搜索了一通kaggle,google. 最后直接clone了别人的一个repo

点击(此处)折叠或打开

  1. git clone https://github.com/timurista/data-analysis


 
			

点击(此处)折叠或打开

  1. import statsmodels.api as sm
  2. import seaborn as sns
  3. import matplotlib.pyplot as plt
  4. import pandas as pd
  5. sns.set()
  6. data=pd.read_csv('data-analysis/python-jupyter/1.01. Simple linear regression.csv')
  7. data.describe()
  8. y=data['GPA']
  9. X=data['SAT']
  10. plt.scatter(X,y)
  11. plt.xlabel('SAT',fontsize=20)
  12. plt.ylabel('GPA', fontsize=20)
  13. plt.show()
  14. x1=sm.add_constant(X)
  15. results=sm.OLS(y,x1).fit()
  16. '''
  17. intercept=0.275
  18. slope=0.0017
  19. coef=coefficient
  20. t: t-statistic
  21. P>|t|: p-value, less than 0.005 menas the variable is significant, so the best value we want is 0.000
  22. '''
  23. print(results.summary())
  24. plt.scatter(X,y)
  25. yhat=0.0017*X+0.275
  26. fig=plt.plot(X, yhat, lw=4, c='orange', label='regression line')
  27. plt.xlabel('SAT', fontsize=20)
  28. plt.ylabel('GPA', fontsize=20)
  29. plt.show()
阅读(7871) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~