gpt4 book ai didi

python - 重新安装sklearn后出现错误

转载 作者:行者123 更新时间:2023-11-30 09:56:39 25 4
gpt4 key购买 nike

将 sklearn 更新到新版本后,我收到以下错误 - 我不知道这是为什么。

    Traceback (most recent call last):
File "/Users/X/Courses/Project/SupportVectorMachine/main.py", line 95, in <module>
y, x = dmatrices(formula, data=finalDataFrame, return_type='matrix')
File "/Library/Python/2.7/site-packages/patsy/highlevel.py", line 297, in dmatrices
NA_action, return_type)
File "/Library/Python/2.7/site-packages/patsy/highlevel.py", line 156, in _do_highlevel_design
return_type=return_type)
File "/Library/Python/2.7/site-packages/patsy/build.py", line 947, in build_design_matrices
value, is_NA = evaluator.eval(data, NA_action)
File "/Library/Python/2.7/site-packages/patsy/build.py", line 85, in eval
return result, NA_action.is_numerical_NA(result)
File "/Library/Python/2.7/site-packages/patsy/missing.py", line 135, in is_numerical_NA
mask |= np.isnan(arr)
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule 'safe'

这是对应的代码。我已经重新安装并安装了从 Numpy 到 scipy patsy 等的所有内容。但没有任何效果。

 # Merging the two dataframes - user and the tweets
finalDataFrame = pandas.merge(twitterDataFrame.reset_index(),twitterUserDataFrame.reset_index(),on=['UserID'],how='inner')
finalDataFrame = finalDataFrame.drop_duplicates()
finalDataFrame['FrequencyOfTweets'] = numpy.all(numpy.isfinite(finalDataFrame['FrequencyOfTweets']))

# model formula, ~ means = and C() lets the classifier know its categorical data.
formula = 'Classifier ~ InReplyToStatusID + InReplyToUserID + RetweetCount + FavouriteCount + Hashtags + UserMentionID + URL + MediaURL + C(MediaType) + UserMentionID + C(PossiblySensitive) + C(Language) + TweetLength + Location + Description + UserAccountURL + Protected + FollowersCount + FriendsCount + ListedCount + UserAccountCreatedAt + FavouritesCount + GeoEnabled + StatusesCount + ProfileBackgroundImageURL + ProfileUseBackgroundImage + DefaultProfile + FrequencyOfTweets'

### create a regression friendly data frame y gives the classifiers, x gives the features and gives different columns for Categorical data depending on variables.
y, x = dmatrices(formula, data=finalDataFrame, return_type='matrix')

## select which features we would like to analyze
X = numpy.asarray(x)

最佳答案

我发现在包含字符串或其他非浮点值的数组上调用 np.isnan 时有时会出现错误。在将 np.arrays 传递给 dmatrices 之前,尝试使用 arr.astype(float) 来转换它们。

此外,您的推文频率列被设置为全 False 或全 True,因为 np.all 返回一个标量。

关于python - 重新安装sklearn后出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24960967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com