问题标签 [categorical-data]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
r - Offsets and categorical variables
Using this dataset:
and building on this question:
How to fit predefined offsets to models containing categorical variables in R
in order to test the validty of a model on another test dataset, I want to take the fitted model from:
and fit it to relationship B:
The response variables are identical in each case.
The above link provides a solution to how to fit an offset for the levels of a categorical variable, which for my data would involve:
However when I check whether this works by specifying these known offsets to a relationship and then checking it with the identical model without offsets specified, thus:
The residuals are different, showing that the method does not work.
I am thus wondering:
1) Does anyone have any other ideas idea how to specify offsets for the levels of a categorical variable? 2) Can you advise on how to specify and offset for the intercept terms for such a varible, in addition to offsets for the levels?
The latter is simple enough for a continuous variable as there is only one intercept:
But it is not clear to me how this would transfer to a categorical variable.
Many thanks.
r - FactoMineR 中的 MCA
我正在使用 FactoMine R 绘制 MCA 图。我的数据表如下所示:
这是我的第一个红色标志......之后,我执行了 MCA 只是为了看看我会得到什么,这就是代码:
然后我在控制台中得到以下信息:
我是使用 R 的新手(如 1 周),但我有使用 SAS 的经验......我不知道我做错了什么以及为什么 R 将我的数据修复到上述结构中(3L、3L、3L.. .) 有没有人知道如何进行?
r - R错误“总和对因素没有意义”
我有一个名为 rRna_RDP_taxonomy_phylum 的文件,其中包含以下数据:
我正在使用此代码在 R 中创建饼图:
我一直在将此代码用于不同的数据文件,并且工作正常,但是使用 adobe 呈现的文件时,它会崩溃并返回以下消息:
我需要了解为什么它会与此文件一起崩溃,以及是否有任何方法可以防止此类错误。
谢谢!
r - 分类数据的朴素贝叶斯分类
我是统计和数据挖掘的新手。我按照这里的例子,效果很好。现在我想将此方法应用于我的数据集,但是,该数据集仅包含分类数据。
R给出以下错误:
我的问题是:我应该进行什么样的转换才能将该方法应用于我的分类数据集?
代码片段
r - GBM 多项式分布,如何使用 predict() 得到预测类?
我正在使用gbm
R 包中的多项分布。当我使用该predict
函数时,我得到一系列值:
但我想获得每个班级发生的概率。如何恢复概率?谢谢你。
r - 在逻辑回归图中可视化分类数据
我正在尝试基于二进制数据作为因变量(直接离开 = 0 或 1)创建逻辑回归图。自变量是连续数据(危险提示的持续时间)、计数数据(危险提示出现的时间)和分类数据(治疗:蔗糖或章鱼胺):
到目前为止,我能够为整个数据集创建两个带有一条拟合线的图表(下图):
然而,我研究的目的是展示两种治疗方法之间的差异。我知道我需要两个类别(即蔗糖和章鱼胺)的斜率和截距值,但Anova()
只为整个数据集提供一个值。所以,我想用两条拟合线创建两个图表:每个处理一个。是否有可能做到这一点,如果可以,怎么做?
r - 将分类变量转换为 R 中的事件计数变量
我正在使用超过 270,000 个观察值的跨国日常数据(我为其生成了一个年份变量),以及本次讨论中感兴趣的变量(PartyCode)的大量缺失值。数据如下所示:
我想将此数据更改为年度数据,采用国家/地区格式:
我的问题是多方面的:
1)如何从分类 PartyCode 变量中提取值以生成我想要的计数变量(对于每个类别)?
值得注意的是,这个数据集有很多分类变量 PartyCode 的缺失值。
python-2.7 - 在 sklearn 0.14 中使用 OneHotEncoder 指定要分类的选择特征
我在 Python 中使用 sklearn 0.14 模块来创建决策树。我希望使用 OneHotEncoder 将一些特征转换为分类特征。根据文档,我应该能够提供一组索引来指示应该转换哪些功能。但是,尝试以下代码:
我收到以下错误:
相反,如果我将数组 [0, 1] 提供给 categorical_features,它可以正常工作并正确转换这两个特征。使用 'all' 到 categorical_features 会出现同样的正确行为。但是,我只希望转换第二个功能而不是第一个。我知道我可以通过一次转换一个功能来手动执行此操作,但我希望使用 OneHotEncoder 的所有优点,因为稍后我将使用更多功能。
python - 从熊猫中具有多个值的列创建假人
我正在寻找一种pythonic方式来处理以下问题。
该pandas.get_dummies()
方法非常适合从数据框的分类列创建虚拟对象。例如,如果列在 中具有值['A', 'B']
,则get_dummies()
创建 2 个虚拟变量并相应地分配 0 或 1。
现在,我需要处理这种情况。单列,我们称之为“标签”,具有类似['A', 'B', 'C', 'D', 'A*C', 'C*D']
. get_dummies()
创建 6 个假人,但我只想要其中的 4 个,这样一行就可以有多个 1。
有没有办法以pythonic方式处理这个问题?我只能想一些逐步的算法来获得它,但这不包括 get_dummies()。谢谢
已编辑,希望更清楚!