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 (将#修改为@)