我已经在Stack Overflow上进行了彻底的搜索,但是找不到此问题的答案。我正在尝试使用适用于Python(3.6.2)的Google Translate API(googletrans 2.2.0),并试图将一组非英语文档翻译成英语。我让Google Translate进行语言检测。这是我的代码:
## newcorpus is a corpus I have created consisting of non-english documents
fileids = newcorpus.fileids
for f in fileids:
p = newcorpus.raw(f)
p = str(p[:15000])
translated_text = translator.translate(p)
print(translated_text)
sleep(10)
Run Code Online (Sandbox Code Playgroud)
我每次都要等待10秒,从而限制了对API的调用。我也一次只喂API 15k个字符,以保持在字符数限制内。
每次运行此代码,都会收到以下错误消息:
## newcorpus is a corpus I have created consisting of non-english documents
fileids = newcorpus.fileids
for f in fileids:
p = newcorpus.raw(f)
p = str(p[:15000])
translated_text = translator.translate(p)
print(translated_text)
sleep(10)
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
python google-translate python-3.x language-translation jsondecoder
我正在使用 Python 中的 statsmodels MixedLM 包估计混合线性模型。拟合模型后,我现在想进行预测,但正在努力理解“预测”方法。
statsmodels 文档 ( http://www.statsmodels.org/dev/generated/statsmodels.regression.mixed_linear_model.MixedLM.predict.html ) 表明 predict 方法采用包含已估计模型参数的数组。我怎样才能检索这个数组?
y = raw_data['dependent_var']
X = raw_data[['var1', 'var2', 'var3']]
groups = raw_data['person_id']
model = sm.MixedLM(endog=y, exog=X, groups=groups)
result = model.fit()
Run Code Online (Sandbox Code Playgroud)