小编juk*_*box的帖子

ValueError:输入包含 NaN、无穷大或对于 dtype('float32') 来说太大的值。为什么?

我已经浏览了所有类似的问题,但没有一个回答我的问题。我使用随机森林分类器,如下所示:

from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier(n_estimators=100, max_depth=2, random_state=0)
clf.fit(X_train, y_train)
clf.predict(X_test)
Run Code Online (Sandbox Code Playgroud)

它给了我这个错误:

ValueError: Input contains NaN, infinity or a value too large for dtype('float32').

但是,当我这样做时,X_train.describe()我没有看到任何缺失值。事实上,实际上,我什至在分割数据之前就已经处理了缺失值。

当我执行以下操作时:

np.where(X_train.values >= np.finfo(np.float32).max)

我得到:

(array([], dtype=int64), array([], dtype=int64))

对于这些命令:

np.any(np.isnan(X_train)) #true
np.all(np.isfinite(X_train)) #false
Run Code Online (Sandbox Code Playgroud)

得到上述结果后,我也尝试了这个:

X_train.fillna(X_train.mean())

但我遇到了同样的错误并且它没有解决任何问题。

请告诉我哪里出错了。谢谢你!

python numpy pandas scikit-learn jupyter

5
推荐指数
1
解决办法
1万
查看次数

How to perform spell check in spacy. Need to find number of wrong words and suggestions if possible

How to perform spell check in spacy. Need to find number of worng words and suggestions if possible. I have tried this page

print('spell check doc_new')
print('-----------------')
print('contextual_spellCheck')
print(doc_new._.contextual_spellCheck)
print('performed_spellCheck')
print(doc_new._.performed_spellCheck)
print('score_spellCheck')
print(doc_new._.score_spellCheck)
print('outcome_spellCheck')
print(doc_new._.outcome_spellCheck)
print(nlp.pipe_names)
-----------------------
Output
contextual_spellCheck
True
performed_spellCheck
True
score_spellCheck
{bok: [('home', 0.25162), ('life', 0.10225), ('job', 0.0533), ('friend', 0.02805), ('place', 0.01896), ('world', 0.01788), ('apartment', 0.01757), ('family', 0.01643), ('house', 0.01583), ('boss', 0.01192)], universty: [('full', 0.24508), ('last', 0.14188), ('first', 0.11419), ('middle', 0.09706), ('real', 0.07817), ('given', 0.04026), ('birth', 0.03326), ('code', …
Run Code Online (Sandbox Code Playgroud)

python spacy

3
推荐指数
1
解决办法
7075
查看次数

如何从字典列表中删除重复项?

我在 python 中有一个字典列表,如下所示:

[{'category': 'software', 'name': 'irssi', 'version': '1.2.0'},
 {'category': 'software', 'name': 'irssi', 'version': '1.1.2'},
 {'category': 'software', 'name': 'hexchat', 'version': '2.14.2'}]
Run Code Online (Sandbox Code Playgroud)

(解析一些数据txt文件)

我想做什么:

如果类别和名称相同,我想保留包条目的第一次出现并删除其余部分,因此最终输出将如下所示:

[{'category': 'software', 'name': 'irssi', 'version': '1.2.0'},
{'category': 'software', 'name': 'hexchat', 'version': '2.14.2'}]
Run Code Online (Sandbox Code Playgroud)

我应该如何实现这一目标?我尝试将字典列表转换为字典,然后迭代它,dict.items()但没有运气。

python dictionary list

2
推荐指数
1
解决办法
4041
查看次数

标签 统计

python ×3

dictionary ×1

jupyter ×1

list ×1

numpy ×1

pandas ×1

scikit-learn ×1

spacy ×1