python - 在 Python 中估计相关性
问题描述
我有一个带有标签和用户名的数据集:
Labels Usernames
1 Londonderry
1 Londoncalling
1 Steveonder43
0 Maryclare_re
1 Patent107391
0 Anonymous
1 _24londonqr
...
我需要证明包含单词 London 和标签 1 的用户名之间存在相关性。为此,我创建了第二个标签以查看单词 London 的位置
for idx, username in df['Usernames']:
if 'London' in username:
df['London'].iloc[idx] = 1
else:
df['London'].iloc[idx] = 0
然后我使用 Pearson 相关系数比较了这些二元变量:
import scipy.stats.pearsonr as rho
corr = rho(df['labels'], df['London'])
但是它不起作用。我在上述步骤中遗漏了什么吗?
解决方案
你Labels
在你的数据框中,但你通过labels
了,我也通过contains
df['London'] = df['Usernames'].str.contains('London').astype(int)
from scipy import stats
stats.pearsonr(df['Labels'], df['London'])
Out[12]: (0.4, 0.37393392381774704)
推荐阅读
- codeigniter - CodeIgniter 登录表单不会重定向到仪表板
- python - pip 将软件包安装在错误的目录中
- discord - 如何在 discord.py 的 cog 内创建后台任务?
- android - 有人知道这个Android类的功能吗?“com.google.apps.tiktok.tracing.db”?
- python - 将信息从 dics 列表解析到系列级别
- r - 如何提取 R 中 GJRM 包中 post.check 函数的 QQPLOT?
- python - LSTM 分类器的准确率低
- firebase - Firebase 分析每小时粒度报告
- sharepoint - 使用 CSOM 将 AD 组添加到 Sharepoint Online 组
- javascript - 为什么传递道具无限循环会使我的应用程序崩溃并且甚至不更新道具?