文章目录
数据分析全过程梳理见
【数据分析入门】python数据分析全过程梳理
多因子与对比分析可视化
目的:展现数据全貌
理论基础
假设检验与方差检验
假设检验
根据一定的假设条件,从样本推断总体,或者推断样本与样本之间关系的一种方法。
根据样本已知的分布性质来推断整体的性质
假设检验的基本思想是“小概率事件”原理,其统计推断方法是带有某种概率性质的反证法。小概率思想是指小概率事件在一次试验中基本上不会发生。反证法思想是先提出检验假设,再用适当的统计方法,利用小概率原理,确定假设是否成立。即为了检验一个假设H0是否正确,首先假定该假设H0正确,然后根据样本对假设H0做出接受或拒绝的决策。如果样本观察值导致了“小概率事件”发生,就应拒绝假设H1,否则应接受假设H1。
假设检验的步骤:
显著性水平越低,要求越高
检验统计量:
t分布,样本区别
f检验,方差分析
卡方检验,四格表检验法,检验两个指标有没有相关性
方差检验
F检验
R5piv5rip5biF5biF,size_17,color_FFFFFF,t_70,g_se,x_16)
独立分布t检验
样本长度可以不一样
相关系数:皮尔逊、斯皮尔曼
n是样本个数
d是排序
只跟相对大小有关
应用于相对比较的情况
回归:线性回归
好的回归,DW值接近2,应该是残差不相关
PCA与奇异值分解
主成分最大的作用:降维
奇异值分解
代码实践
交叉分析
分组分析
相关分析
因子分析
总结
代码实现
相关性
import pandas as pd
s1=pd.Series([0.1,0.2,1.1,2.4,1.3,0.3,0.5])
s2=pd.Series([0.5,0.4,1.2,2.5,1.1,0.7,0.1])
s1.corr(s2)
0.9333729600465923
s1.corr(s2,method="spearman")
0.7142857142857144
df=pd.DataFrame([s1,s2])
df.corr()
df=pd.DataFrame(np.array([s1,s2]).T)
df.corr()
x=np.arange(10).astype(np.float).reshape((10,1))
C:\ProgramData\Miniconda3\lib\site-packages\ipykernel_launcher.py:1: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
"""Entry point for launching an IPython kernel.
y=x*3+4+np.random.random((10,1))
线性回归
from sklearn.linear_model import LinearRegression
reg=LinearRegression()
res=reg.fit(x,y)
y_pred=reg.predict(x)
reg.coef_
array([[2.93514572]])
reg.intercept_
array([4.70737715])
PCA
data=np.array([np.array([2.5,0.5,2.2, 1.9,3.1,2.3,2, 1,1.5,1.1]),
np.array([2.4,0.7,2.9,2.2,3,2.7,1.6,1.1, 1.6,0.9])]).T
data
array([[2.5, 2.4],
[0.5, 0.7],
[2.2, 2.9],
[1.9, 2.2],
[3.1, 3. ],
[2.3, 2.7],
[2. , 1.6],
[1. , 1.1],
[1.5, 1.6],
[1.1, 0.9]])
from sklearn.decomposition import PCA