OLS Regression: TypeError: ufunc 'isfinite' not supported for the input types

Viewed 96

I am aiming to execute a regression analysis on the diffusion of tweets compared to hashtags that are incorporated in tweets.

When executing this code

#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())

the following error pops up

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''

From other questions I noticed this was a dtype error and that I had to change my dtype to float. However both tagscore as well as diffusion_count are already floats

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

Where does this error arise? and how can it be resolved?

0 Answers
Related