【发布时间】:2019-10-09 13:11:09
【问题描述】:
准备一个小玩具示例:
import pandas as pd
import numpy as np
high, size = 100, 20
df = pd.DataFrame({'perception': np.random.randint(0, high, size),
'age': np.random.randint(0, high, size),
'outlook': pd.Categorical(np.tile(['positive', 'neutral', 'negative'], size//3+1)[:size]),
'smokes': pd.Categorical(np.tile(['lots', 'little', 'not'], size//3+1)[:size]),
'outcome': np.random.randint(0, high, size)
})
df['age_range'] = pd.Categorical(pd.cut(df.age, range(0, high+5, size//2), right=False,
labels=["{0} - {1}".format(i, i + 9) for i in range(0, high, size//2)]))
np.random.shuffle(df['smokes'])
这会给你类似的东西:
In [2]: df.head(10)
Out[2]:
perception age outlook smokes outcome age_range
0 13 65 positive little 22 60 - 69
1 95 21 neutral lots 95 20 - 29
2 61 53 negative not 4 50 - 59
3 27 98 positive not 42 90 - 99
4 55 99 neutral little 93 90 - 99
5 28 5 negative not 4 0 - 9
6 84 83 positive lots 18 80 - 89
7 66 22 neutral lots 35 20 - 29
8 13 22 negative lots 71 20 - 29
9 58 95 positive not 77 90 - 99
目标:找出outcome 的可能性,给定{perception, age, outlook, smokes}。
次要目标:弄清楚每一列对于确定outcome 的重要性。
第三个目标:证明关于分布的属性(这里我们是随机生成的,所以随机分布应该暗示null hypothesis是真的?)
显然,这些都是statistical hypothesis testing 可以找到的问题。在 pandas 中回答这些问题的正确方法是什么?
【问题讨论】:
-
One-hot 编码器和softmax?
-
很想在 TensorFlow 中为此构建一个 NN。但是,我确实想获得 p 值以及所有这些。所以最终可能会采用两种方法,p 值方法对于 pandas/statsmodel/numpy/researchpy 来说似乎已经成熟。我是什么意思?
-
您提出了一个重要问题,但现在您离题了。建议暂时忘记构建模型,而是专注于
categorical variable treatment的统计上正确的方法。通过询问如何衡量分类变量和连续变量之间的相互作用,可以进一步丰富这个问题。想想吧。 -
这听起来像是one versus all classification 的一个很好的用例。对于您的预测器,您可以使用 pd.get_dummies 或 sklearn 中的一个热编码器。
-
statsmodels 的线性回归将为您提供每个特征的 p 值。如果您正在寻找对回归预测的信心,请查看:docs.seldon.io/projects/alibi/en/v0.2.0/methods/…,也许您可以将其调整为回归而不是分类
标签: pandas numpy scipy anova hypothesis-test