ImportError: cannot import name VarianceThreshold
ImportError: cannot import name VarianceThreshold
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
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