【问题标题】:Variable inflation factor not working with dataframes python可变通货膨胀因子不适用于数据框python
【发布时间】:2018-06-26 09:00:34
【问题描述】:

我有一个(1460, 76) 大小的数据集。它目前在 pandas Dataframe 中,它有各种数据类型:int, float, object。我正在尝试在此数据帧上运行 VIF 函数以获取我的变量的相关性,但是它抛出了这个错误:

TypeError: '>=' not supported between instances of 'str' and 'int'

VIF 代码:

vif = [variance_inflation_factor(df.values, i) for i in range(df.shape[1])]
print(vif)

可能是什么原因,是因为我的数据中有字符串吗?

【问题讨论】:

    标签: python pandas numpy statistics statsmodels


    【解决方案1】:

    听起来您的某些数据存储为字符串而不是数字数据类型。尝试在您的数据框上使用pandas.to_numeric

    Example applying to_numeric to an entire data frame

    【讨论】:

    • 是的,我做的是字符串数据。有办法吗?
    猜你喜欢
    • 1970-01-01
    • 2012-04-11
    • 2017-07-28
    • 2019-10-31
    • 1970-01-01
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    相关资源
    最近更新 更多