目录
5.3 卡方分析和方差分析
(1)卡方检验
import pandas as pd
from scipy import stats
import os
os.chdir(r'C:\Users\Administrator.DESKTOP-0L8IC5U\Desktop\数据分析\data')
insurance = pd.read_csv('train.csv', encoding='utf-8', dtype={'Gender': 'str'})
cross_table = pd.crosstab(insurance.Gender, insurance.Vintage, margins=True)
# pd.crosstab(insurance.children, insurance.insuranceclaim, normalize='index')
stats.chi2_contingency(cross_table)