回归_英国酒精和香烟关系

 

sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程)

 

https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campaign=commission&utm_source=cp-400000000398149&utm_medium=share

 

 

数据统计分析联系:QQ:231469242

英国酒精和香烟官网

http://lib.stat.cmu.edu/DASL/Stories/AlcoholandTobacco.html

Story Name: Alcohol and TobaccoImage: Scatterplot of Alcohol vs. Tobacco, with Northern Ireland marked with a blue X.

 

Story Topics: Consumer , HealthDatafile Name: Alcohol and TobaccoMethods: Correlation , Dummy variable , Outlier , Regression , ScatterplotAbstract: Data from a British government survey of household spending may be used to examine the relationship between household spending on tobacco products and alcholic beverages. A scatterplot of spending on alcohol vs. spending on tobacco in the 11 regions of Great Britain shows an overall positive linear relationship with Northern Ireland as an outlier. Northern Ireland's influence is illustrated by the fact that the correlation between alcohol and tobacco spending jumps from .224 to .784 when Northern Ireland is eliminated from the dataset.

This dataset may be used to illustrate the effect of a single influential observation on regression results. In a simple regression of alcohol spending on tobacco spending, tobacco spending does not appear to be a significant predictor of tobacco spending. However, including a dummy variable that takes the value 1 for Northern Ireland and 0 for all other regions results in significant coefficients for both tobacco spending and the dummy variable, and a high R-squared.

 

 

 

 

两个模块算出的R平方值一样的

 

 

 

# -*- coding: utf-8 -*-
"""
python3.0
Alcohol and Tobacco 酒精和烟草的关系
http://lib.stat.cmu.edu/DASL/Stories/AlcoholandTobacco.html
很多时候,数据读写不一定是文件,也可以在内存中读写。
StringIO顾名思义就是在内存中读写str。
要把str写入StringIO,我们需要先创建一个StringIO,然后,像文件一样写入即可
"""import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import statsmodels.formula.api as sm
from sklearn.linear_model import LinearRegression
from scipy import statslist_alcohol=[6.47,6.13,6.19,4.89,5.63,4.52,5.89,4.79,5.27,6.08,4.02]
list_tobacco=[4.03,3.76,3.77,3.34,3.47,2.92,3.20,2.71,3.53,4.51,4.56]
plt.plot(list_tobacco,list_alcohol,'ro')
plt.ylabel('Alcohol')
plt.ylabel('Tobacco')
plt.title('Sales in Several UK Regions')
plt.show()data=pd.DataFrame({'Alcohol':list_alcohol,'Tobacco':list_tobacco})result = sm.ols('Alcohol ~ Tobacco', data[:-1]).fit()
print(result.summary())

 

 

 

python2.7

 

# -*- coding: utf-8 -*-
#斯皮尔曼等级相关(Spearman’s correlation coefficient for ranked data)
import numpy as np
import scipy.stats as stats
from scipy.stats import f
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.stats.diagnostic import lillifors
import normality_checky=[6.47,6.13,6.19,4.89,5.63,4.52,5.89,4.79,5.27,6.08]
x=[4.03,3.76,3.77,3.34,3.47,2.92,3.20,2.71,3.53,4.51]
list_group=[x,y]
sample=len(x)#数据可视化
plt.plot(x,y,'ro')
#斯皮尔曼等级相关,非参数检验
def Spearmanr(x,y):print"use spearmanr,Nonparametric tests"#样本不一致时,发出警告if len(x)!=len(y):print "warming,the samples are not equal!"r,p=stats.spearmanr(x,y)print"spearman r**2:",r**2print"spearman p:",pif sample<500 and p>0.05:print"when sample < 500,p has no mean(>0.05)"print"when sample > 500,p has mean"#皮尔森 ,参数检验
def Pearsonr(x,y):print"use Pearson,parametric tests"r,p=stats.pearsonr(x,y)print"pearson r**2:",r**2print"pearson p:",pif sample<30:print"when sample <30,pearson has no mean"#kendalltau非参数检验
def Kendalltau(x,y):print"use kendalltau,Nonparametric tests"r,p=stats.kendalltau(x,y)print"kendalltau r**2:",r**2print"kendalltau p:",p#选择模型
def mode(x,y):#正态性检验Normal_result=normality_check.NormalTest(list_group)print "normality result:",Normal_resultif len(list_group)>2:Kendalltau(x,y)if Normal_result==False:Spearmanr(x,y)Kendalltau(x,y)if Normal_result==True:   Pearsonr(x,y)mode(x,y)
'''
x=[50,60,70,80,90,95]
y=[500,510,530,580,560,1000]
use shapiro:
data are normal distributed
use shapiro:
data are not normal distributed
normality result: False
use spearmanr,Nonparametric tests
spearman r: 0.942857142857
spearman p: 0.00480466472303
use kendalltau,Nonparametric tests
kendalltau r: 0.866666666667
kendalltau p: 0.0145950349193#肯德尔系数测试
x=[3,5,2,4,1]
y=[3,5,2,4,1]
z=[3,4,1,5,2]
h=[3,5,1,4,2]
k=[3,5,2,4,1]
'''

 

 python2.7

# -*- coding: utf-8 -*-
'''
Author:Toby
QQ:231469242,all right reversed,no commercial use
normality_check.py
正态性检验脚本'''import scipy
from scipy.stats import f
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
# additional packages
from statsmodels.stats.diagnostic import lillifors#正态分布测试
def check_normality(testData):#20<样本数<50用normal test算法检验正态分布性if 20<len(testData) <50:p_value= stats.normaltest(testData)[1]if p_value<0.05:print"use normaltest"print "data are not normal distributed"return  Falseelse:print"use normaltest"print "data are normal distributed"return True#样本数小于50用Shapiro-Wilk算法检验正态分布性if len(testData) <50:p_value= stats.shapiro(testData)[1]if p_value<0.05:print "use shapiro:"print "data are not normal distributed"return  Falseelse:print "use shapiro:"print "data are normal distributed"return Trueif 300>=len(testData) >=50:p_value= lillifors(testData)[1]if p_value<0.05:print "use lillifors:"print "data are not normal distributed"return  Falseelse:print "use lillifors:"print "data are normal distributed"return Trueif len(testData) >300: p_value= stats.kstest(testData,'norm')[1]if p_value<0.05:print "use kstest:"print "data are not normal distributed"return  Falseelse:print "use kstest:"print "data are normal distributed"return True#对所有样本组进行正态性检验
def NormalTest(list_groups):for group in list_groups:#正态性检验status=check_normality(group)if status==False :return Falsereturn True'''
group1=[2,3,7,2,6]
group2=[10,8,7,5,10]
group3=[10,13,14,13,15]
list_groups=[group1,group2,group3]
list_total=group1+group2+group3
#对所有样本组进行正态性检验   
NormalTest(list_groups)
'''

 

python风控评分卡建模和风控常识(博客主亲自录制视频教程)

https://study.163.com/course/introduction.htm?courseId=1005214003&utm_campaign=commission&utm_source=cp-400000000398149&utm_medium=share

转载于:https://www.cnblogs.com/webRobot/p/7140749.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/254085.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C# ini文件读写函数

namespace Tools {class IniOperate{[DllImport("kernel32")]private static extern int GetPrivateProfileString(string section, string key,

Visual studio内存泄露检查工具--BoundsChecker

BoundsChecker是一个Run-Time错误检测工具&#xff0c;它主要定位程序在运行时期发生的各种错误。 BoundsChecker能检测的错误包括&#xff1a; 1&#xff09;指针操作和内存、资源泄露错误&#xff0c;比如&#xff1a;内存泄露&#xff1b;资源泄露&#xff…

【转】如何用Maven创建web项目(具体步骤)

使用eclipse插件创建一个web project 首先创建一个Maven的Project如下图 我们勾选上Create a simple project &#xff08;不使用骨架&#xff09; 这里的Packing 选择 war的形式 由于packing是war包&#xff0c;那么下面也就多出了webapp的目录 由于我们的项目要使用eclipse发…

CST光源控制卡简单操作C#程序

namespace Machine {class LightCST{private SerialPort serialPort ;public LightCST(){serialPort = new SerialPort();}

可能是目前最详细的Redis内存模型及应用解读

Redis是目前最火爆的内存数据库之一&#xff0c;通过在内存中读写数据&#xff0c;大大提高了读写速度&#xff0c;可以说Redis是实现网站高并发不可或缺的一部分。 我们使用Redis时&#xff0c;会接触Redis的5种对象类型&#xff1a;字符串、哈希、列表、集合、有序集合。丰富…

bootcmd 和bootargs

看到这个标题&#xff0c;可能觉得这个并没有什么的&#xff0c;其实不然&#xff0c;编好了u-boot了&#xff0c;但是如何来使用确不是那么简单的&#xff0c;想当初我将uboot制作出来后以为全部都搞定了&#xff0c;屁颠屁颠的烧到板子上后可系统就是起不来&#xff0c;为什么…

名词解释(容器、并发,插件,脚本)及程序对象的创建和注释文档

一、专有名词 1‘  容器 创建一种对象类型&#xff0c;持有对其他对象的引用&#xff0c;被称为容器的新对象。在任何时候都可以扩充自己以容纳置于其中的所有东西。 java在其标准类库中包含了大量的容器。在某些类库中&#xff0c;一两个通用容器足以满足所有的需要&#xf…

POJ 1696 Space Ant 极角排序(叉积的应用)

题目大意&#xff1a;给出n个点的编号和坐标&#xff0c;按逆时针方向连接着n个点&#xff0c;按连接的先后顺序输出每个点的编号。 题目思路&#xff1a;Cross&#xff08;a,b&#xff09;表示a,b的叉积&#xff0c;若小于0&#xff1a;a在b的逆时针方向&#xff0c;若大于0a在…

C#模板匹配创建模板与查找模板函数

class ShapeModulInspect{/// <summary>/// /// </summary>/// <param name="InspectImg">图像</param>/// <param name="ModulRoi">ROI</param>/// <param name="AngleStart">起始角</param>/…

SuperMap iDesktop之导入数据

SuperMap作为一个平台软件有自己的数据格式&#xff0c;现要将ESRI的SHP数据导入到SuperMap的udb数据库中&#xff0c;可以完成导入&#xff0c;但也不得不说几点问题。 下面是ArcGIS中批量导入SHP的操作界面。 比较分析 &#xff08;1&#xff09;界面简洁性 明显ArcGIS要简洁…

Ajax教程

AJAX AJAX Asynchronous JavaScript and XML&#xff08;异步的 JavaScript 和 XML&#xff09;。 AJAX 不是新的编程语言&#xff0c;而是一种使用现有标准的新方法。 AJAX 是与服务器交换数据并更新部分网页的艺术&#xff0c;在不重新加载整个页面的情况下。 AJAX 是一种在…

dm365 resize

DM368支持视频的缩放功能&#xff0c;例如DM365可以编码一个720P的&#xff0c;同时可以以任意分辨率&#xff08;小于720P的分辨率&#xff09;输出。其中有两种模式&#xff1a;IMP_MODE_SINGLE_SHOT&#xff0c;IMP_MODE_CONTINUOUS. 在用dm365的时候&#xff0c;用resizer…

SSH

http://www.cnblogs.com/hoobey/p/5512924.html struts --- 控制器 hibernate 操作数据库 spring 解耦 Struts 、 spring 、 Hibernate 在各层的作用 1 &#xff09; struts 负责 web 层 . ActionFormBean 接收网页中表单提交的数据&#xff0c;然后通过 Action 进…

C#halcon点拟合圆形函数

public bool FitCircle(double[] X, double[] Y, out double RcX, out double RcY, out double R){t

MyBatis 实践 -配置

MyBatis 实践标签&#xff1a; Java与存储 Configuration mybatis-configuration.xml是MyBatis的全局配置文件(文件名称随意),其配置内容和顺序例如以下: properties : 属性(文件)载入/配置settings : 全局配置參数typeAliases : 定义类型别名typeHandlers : 类型处理器objectF…

DM365视频处理流程/DM368 NAND Flash启动揭秘

DM365的视频处理涉及到三个相关处理器&#xff0c;分别是视频采集芯片、ARM处理器和视频图像协处理器&#xff08;VICP&#xff09;&#xff0c;整个处理流程由ARM核协调。视频处理主要涉及三个处理流程&#xff0c;分别是视频采集、视频编码和对编码后的视频的处理&#xff0c…

系统的Drawable(四)-LayerListDrawable

系统的Drawable(四)-LayerListDrawable 学习自 https://blog.csdn.net/u014695188/article/details/52815444 LayerListDrawable 漫谈 使用layer-list可以将多个drawable按照顺序层叠在一起显示&#xff0c;默认情况下&#xff0c;所有的item中的drawable都会自动根据它附上vie…

图像处理:镜头频率(衍射极限) 和 相机采样:显微镜的采样定理

采样定理大家都知道&#xff0c;相信不用多说。 我自己写下来给自己看。 下面&#xff0c;我总结 大家平时照相的镜头或者显微镜的物镜的情况下&#xff1a; 采样频率是指图像在数字化的时候的过程&#xff0c;实际上就是我们相机感光元件CCD或者CMOS的一个个小像元把模拟的连续…

【练习】使用事务控制语句

1.使用show engines 命令确定系统中是否有任何事务存储引擎可用以及哪个是默认引擎。 2.使用set autocommit 语句启用autocommit。 3.为使用world数据库做准备&#xff0c;确认city表使用事务存储引擎innodb。 4.使用start transaction 语句显式启动新事务。 5.删除一行。 6.使…

老男孩Day1作业(一):编写登录接口

要求&#xff1a;编写登录接口 1. 输入用户名和密码 2. 认证成功后显示欢迎信息 3. 输错三次后锁定 1&#xff09;编写思路 编写思路参考下面GitHub链接中的流程图 https://github.com/ChuixinZeng/PythonStudyCode/blob/master/PythonCode-OldBoy/Day1/作业/Day1_作业_登录接口…