我已经在我的 Mac 中安装了 pyenv 来管理不同的 python 版本。
之前,我有系统默认的 python 2.7/Library/Frameworks/Python.framework/Versions/2.7/
位于/usr/local/bin/python3
现在,我安装了位于 /Users/hao/.pyenv/shims/python2
我只是好奇,当我想使用“pip”命令安装某个库时,如何确保将库安装到正确的 python 中?例如,我想使用 'pip' 将 Torch 或 tensorflow 安装到 pyenv python 2.7.14 中。但不想将它们安装到系统默认 python 中。另外,如何更改pip3版本?
这里我使用which pipand which pip3,结果是:
haos-mbp:~ hao$ which pip
/Users/hao/.pyenv/shims/pip
haos-mbp:~ hao$ which pip3
/usr/local/bin/pip3
Run Code Online (Sandbox Code Playgroud) 做天真的贝叶斯分类时,有没有人知道如何设置alpha的参数?
例如,我首先使用词袋来构建特征矩阵,矩阵的每个单元都是单词的计数,然后我用tf(术语频率)对矩阵进行归一化.
但是当我使用朴素贝叶来构建分类器模型时,我选择使用多项式NB(我认为这是正确的,而不是伯努利和高斯).默认的alpha设置是1.0(文档说拉普拉斯平滑,我不知道是什么).
结果非常糟糕,就像只有21%的人回忆起找到积极的类(目标类).但是当我设置alpha = 0.0001(我随机选择)时,结果得到95%的回忆得分.
此外,我检查了多项式NB 公式,我认为这是因为alpha问题,因为如果我使用单词计数作为特征,则alpha = 1不会影响结果,但是,因为tf介于0- 1,alpha = 1确实会影响这个公式的结果.
我也测试了结果不使用tf,只使用了一堆字数,结果也是95%,那么,有没有人知道如何设置alpha值?因为我必须使用tf作为特征矩阵.
谢谢.
我想通过使用sklearn对文本进行分类。首先,我使用词袋训练数据,词袋的功能确实很大,超过10000个功能,因此我通过使用SVD将该功能减少到100。
但是在这里我想添加一些其他功能,例如单词数量,肯定单词数量,代词数量等。额外的功能仅少了10个功能,而与100个单词袋功能相比确实很小
在这种情况下,我提出两个问题:
假设我有很多numpy数组:
a = ([1,2,3,4,5])
b = ([2,3,4,5,6])
c = ([3,4,5,6,7])
Run Code Online (Sandbox Code Playgroud)
我想生成一个新的二维数组:
d = ([[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7]])
Run Code Online (Sandbox Code Playgroud)
我应该编码什么?我尝试过使用:
d = np.concatenate((a,b),axis=0)
d = np.concatenate((d,c),axis=0)
Run Code Online (Sandbox Code Playgroud)
它返回:
d = ([1,2,3,4,5,2,3,4,5,6,3,4,5,6,7])
Run Code Online (Sandbox Code Playgroud) 我实现了用于文本分类的 fastText,链接https://github.com/facebookresearch/fastText/blob/master/tutorials/supervised-learning.md 我想知道 precision@1 或 P@5 是什么意思?我做了二元分类,但我测试了不同的数字,我不明白结果:
haos-mbp:fastText hao$ ./fasttext test trainmodel.bin train.valid 2
N 312
P@2 0.5
R@2 1
Number of examples: 312
haos-mbp:fastText hao$ ./fasttext test trainmodel.bin train.valid 1
N 312
P@1 0.712
R@1 0.712
Number of examples: 312
haos-mbp:fastText hao$ ./fasttext test trainmodel.bin train.valid 3
N 312
P@3 0.333
R@3 1
Number of examples: 312
Run Code Online (Sandbox Code Playgroud) 我有三个词典(或更多):
A = {'a':1,'b':2,'c':3,'d':4,'e':5}
B = {'b':1,'c':2,'d':3,'e':4,'f':5}
C = {'c':1,'d':2,'e':3,'f':4,'g':5}
Run Code Online (Sandbox Code Playgroud)
如何获取三个词典中每个键的平均值的字典?
例如,给定上面的词典,输出将是:
{'a':1/1, 'b':(2+1)/2, 'c':(3+2+1)/3, 'd':(4+3+2)/3, 'e':(5+4+3)/3, 'f':(5+4)/2, 'g':5/1}
Run Code Online (Sandbox Code Playgroud) 我是Python的新手,试图编写一个爬行程序; 我想使用Beautiful Soup从BBC新闻中抓取一些数据.
但是当我使用Firebug检查元素时,我发现此页面中的HTML没有URL链接.
<li class="">
<a class="navigation-wide-list__link navigation-arrow--open" data-panel-id="js-navigation-panel-World" href="/news/world">
<span>World</span>
</a>
Run Code Online (Sandbox Code Playgroud)
在href = '/news/world',它没有显示真正的URL链接.如果我想抓取此网页中的所有链接,该怎么办?这是因为该网站使用的是Javascript吗?
我有两个列表,A是单词列表,例如[“hello”,“world”,……],Len(A)是10000。列表B包含与A对应的所有预训练向量,这是一个[10000,512],512是向量维度。我想将两个列表转换为gensim word2vec模型格式,以便稍后加载模型,例如model = Word2Vec.load("word2vec.model")我应该怎么做?
我想升级scipy.我使用pip install scipy --upgrade来做到这一点,但是这里有错误,我应该怎么解决这个问题?
Installing collected packages: scipy
Found existing installation: scipy 0.13.0b1
DEPRECATION: Uninstalling a distutils installed project (scipy) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling scipy-0.13.0b1:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 778, in install
requirement.uninstall(auto_confirm=True) …Run Code Online (Sandbox Code Playgroud) python ×5
pip ×2
scikit-learn ×2
arrays ×1
dictionary ×1
fasttext ×1
gensim ×1
html ×1
html-parsing ×1
javascript ×1
naivebayes ×1
nlp ×1
numpy ×1
precision ×1
pyenv ×1
scipy ×1
word2vec ×1