是否有用于训练对数线性模型的python软件包?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了是否有用于训练对数线性模型的python软件包?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2292字,纯文字阅读大概需要4分钟。
内容图文
![是否有用于训练对数线性模型的python软件包?](/upload/InfoBanner/zyjiaocheng/677/1ca1acad6712415a89f33fa0eb7f1211.jpg)
有谁知道python中是否有用于训练loglinear模型的现有软件包?我有一个包含2000个变量和1000条记录的数据集.我正在寻找使用对数线性模型来估计频率.
解决方法:
如果使用旧版本的SciPy(即0.10或更早版本),则可以使用scipy.maxentropy(在NLP中,MaxEnt =最大熵建模=对数线性模型).在发布0.11.0版本时,该模块已从SciPy中删除,SciPy团队随后使用sklearn.linear_model.LogisticRegression替换了advised(请注意,both对数线性模型和逻辑回归是generalized linear models的示例,其中线性预测变量之间的关系).
使用SciPy的最大熵模块的Example(已在SciPy 0.11.0中删除):
#!/usr/bin/env python
""" Example use of the maximum entropy module:
Machine translation example -- English to French -- from the paper 'A
maximum entropy approach to natural language processing' by Berger et
al., 1996.
Consider the translation of the English word 'in' into French. We
notice in a corpus of parallel texts the following facts:
(1) p(dans) + p(en) + p(a) + p(au cours de) + p(pendant) = 1
(2) p(dans) + p(en) = 3/10
(3) p(dans) + p(a) = 1/2
This code finds the probability distribution with maximal entropy
subject to these constraints.
"""
__author__ = 'Ed Schofield'
__version__= '2.1'
from scipy import maxentropy
a_grave = u'\u00e0'
samplespace = ['dans', 'en', a_grave, 'au cours de', 'pendant']
def f0(x):
return x in samplespace
def f1(x):
return x=='dans' or x=='en'
def f2(x):
return x=='dans' or x==a_grave
f = [f0, f1, f2]
model = maxentropy.model(f, samplespace)
# Now set the desired feature expectations
K = [1.0, 0.3, 0.5]
model.verbose = True
# Fit the model
model.fit(K)
# Output the distribution
print "\nFitted model parameters are:\n" + str(model.params)
print "\nFitted distribution is:"
p = model.probdist()
for j in range(len(model.samplespace)):
x = model.samplespace[j]
print ("\tx = %-15s" %(x + ":",) + " p(x) = "+str(p[j])).encode('utf-8')
# Now show how well the constraints are satisfied:
print
print "Desired constraints:"
print "\tp['dans'] + p['en'] = 0.3"
print ("\tp['dans'] + p['" + a_grave + "'] = 0.5").encode('utf-8')
print
print "Actual expectations under the fitted model:"
print "\tp['dans'] + p['en'] =", p[0] + p[1]
print ("\tp['dans'] + p['" + a_grave + "'] = " + str(p[0]+p[2])).encode('utf-8')
# (Or substitute "x.encode('latin-1')" if you have a primitive terminal.)
其他意见:http://homepages.inf.ed.ac.uk/lzhang10/maxent.html
内容总结
以上是互联网集市为您收集整理的是否有用于训练对数线性模型的python软件包?全部内容,希望文章能够帮你解决是否有用于训练对数线性模型的python软件包?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。