Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 导入错误:无法导入名称差异阈值_Python_Python 2.7_Machine Learning_Scikit Learn_Bigdata - Fatal编程技术网

Python 导入错误:无法导入名称差异阈值

Python 导入错误:无法导入名称差异阈值,python,python-2.7,machine-learning,scikit-learn,bigdata,Python,Python 2.7,Machine Learning,Scikit Learn,Bigdata,scikit learn似乎有效,但当我成功时: from sklearn.feature_selection import VarianceThreshold 我得到了以下错误: 导入错误:无法导入名称差异阈值 如何绕过这个?我是Python的新手,所以我不知道该怎么做 我按照这里的建议,按进口顺序玩,但运气不好 import sys import pandas as pd import numpy as np import operator from sklearn.feature_sel

scikit learn似乎有效,但当我成功时:

from sklearn.feature_selection import VarianceThreshold
我得到了以下错误:

导入错误:无法导入名称差异阈值

如何绕过这个?我是Python的新手,所以我不知道该怎么做

我按照这里的建议,按进口顺序玩,但运气不好

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'

您可以通过捕获异常来绕过

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

您可以通过捕获异常来绕过

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

所以,我不可能真正使用VarianceThreshold,对吧/从documnetation,您正在正确导入模块。您可以尝试python-c'import-sklearn;打印(sklearn.feature\u selection.VarianceThreshold)
AttributeError:'module'对象没有属性'feature\u selection'
。好的,谢谢。所以,我不可能真正使用VarianceThreshold,对吗/从documnetation,您正在正确导入模块。您可以尝试python-c'import-sklearn;打印(sklearn.feature\u selection.VarianceThreshold)
AttributeError:'module'对象没有属性'feature\u selection'
。好的,谢谢。同样的问题。你使用的是什么操作系统?@GeorgeWS发布时我使用的是Ubuntu 14.04,64位。好的。我昨天在Ubuntu 14.04.4上使用了这个功能,但现在无法使用了。我完全不知道你为什么会遇到问题。你可以发布一个新问题,或者如果你认为我的问题可以扩展,你应该悬赏并编辑我的问题。我可能知道@GeorgeWS!既然你们提到了这一点,那个时候我的项目的最后期限很快就要到了,所以不,我继续前进。也许这仍然是一个活跃的问题……这里也有同样的问题。你使用的是什么操作系统?@GeorgeWS发布时我使用的是Ubuntu 14.04,64位。好的。我昨天在Ubuntu 14.04.4上使用了这个功能,但现在无法使用了。我完全不知道你为什么会遇到问题。你可以发布一个新问题,或者如果你认为我的问题可以扩展,你应该悬赏并编辑我的问题。我可能知道@GeorgeWS!既然你们提到了这一点,那个时候我的项目的最后期限很快就要到了,所以不,我继续前进。也许这仍然是一个活跃的问题。。。