scikit-learn 似乎有效,但是当我这样做时:
from sklearn.feature_selection import VarianceThreshold
我收到以下错误:
ImportError: cannot import name VarianceThreshold
如何绕过这个?我是Python新手,所以我不知道该怎么做。
我按照此处建议的导入顺序进行了操作:ImportError: Cannot import name X ,但运气不佳。
import sys
import pandas as pd
import numpy as np
import operator
from sklearn.feature_selection import VarianceThreshold
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.feature_extraction.text import HashingVectorizer
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.preprocessing import normalize
from sklearn import decomposition
<小时/>
我也得到了这个:
code/python/k_means/serial_version$ python -c 'import sklearn; print(sklearn.VarianceThreshold)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'VarianceThreshold'
<小时/>
版本:
>>> import sklearn
>>> sklearn.__version__
'0.14.1'
最佳答案
可以通过捕获异常来绕过
try:
from sklearn.feature_selection import VarianceThreshold
except:
pass # it will catch any exception here
如果您只想捕获属性错误异常,请使用下面的
try:
from sklearn.feature_selection import VarianceThreshold
except AttributeError:
pass # catches only Attribute Exception
关于python - 导入错误: cannot import name VarianceThreshold,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35237289/