回歸_英國酒精和香煙關系

?

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.pswp.cn/news/254085.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/254085.shtml
英文地址,請注明出處:http://en.pswp.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_作業_登錄接口…