微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

OLS 回归:类型错误:输入类型不支持 ufunc 'isfinite'

如何解决OLS 回归:类型错误:输入类型不支持 ufunc 'isfinite'

我的目标是对推文的传播与推文中包含的主题标签进行回归分析。

执行这段代码

#Changing X and y to arrays using Numpy# 
x = np.array(hashtag_df['tagscore'])
y = np.array(hashtag_df['diffusion_count'])

#Adding a constant to x to execute the analysis
x = sm.add_constant(x)

#Create and fit model for the analysis
modelsm = sm.OLS(y,X)

smresults = modelsm.fit()

#Print a summary of the model results
print (smresults.summary())

弹出如下错误

TypeError: ufunc 'isfinite' not supported for the input types,and the inputs Could not be safely coerced to any supported types according to the casting rule ''safe''

从其他问题我注意到这是一个 dtype 错误,我不得不将我的 dtype 更改为浮动。然而,tagscore 和diffusion_count 都已经是浮点数

hashtag_df.dtypes
id                   int64
taglist             object
diffusion_count    float64
tagscore           float64
dtype: object

这个错误是哪里出现的?以及如何解决

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。