简体   繁体   English

Cloud ML Engine和Scikit-Learn:'LatentDirichletAllocation'对象没有属性'predict'

[英]Cloud ML Engine and Scikit-Learn: 'LatentDirichletAllocation' object has no attribute 'predict'

I'm implementing simple Scikit-Learn Pipeline to perform LatentDirichletAllocation in Google Cloud ML Engine. 我正在实施简单的Scikit-Learn Pipeline以在Google Cloud ML Engine中执行LatentDirichletAllocation Goal is to predict topics from new data. 目标是从新数据预测主题。 Here is the code for generating pipeline: 以下是生成管道的代码:

from sklearn.feature_extraction.text import CountVectorizer
from sklearn.decomposition import LatentDirichletAllocation
from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from sklearn.datasets import fetch_20newsgroups

dataset = fetch_20newsgroups(shuffle=True, random_state=1,
                             remove=('headers', 'footers', 'quotes'))
train, test = train_test_split(dataset.data[:2000])

pipeline = Pipeline([
    ('CountVectorizer', CountVectorizer(
        max_df          = 0.95,
        min_df          = 2,
        stop_words      = 'english')),
    ('LatentDirichletAllocation', LatentDirichletAllocation(
        n_components    = 10,
        learning_method ='online'))
])

pipeline.fit(train)

Now (if I have understood correctly) to predict topics for test data I can run: 现在(如果我已经正确理解)预测测试数据的主题我可以运行:

pipeline.transform(test)

However, when uploading pipeline to Google Cloud Storage and trying to use it to produce local predictions with Google Cloud ML Engine I get error that says LatentDirichletAllocation has no attribute predict . 但是,在将管道上传到Google云端存储并尝试使用它来使用Google Cloud ML Engine生成本地预测时,我会收到错误消息,指出LatentDirichletAllocation没有属性predict

gcloud ml-engine local predict \
    --model-dir=$MODEL_DIR \
    --json-instances $INPUT_FILE \
    --framework SCIKIT_LEARN
...
"Exception during sklearn prediction: " + str(e)) cloud.ml.prediction.prediction_utils.PredictionError: Failed to run the provided model: Exception during sklearn prediction: 'LatentDirichletAllocation' object has no attribute 'predict' (Error code: 2)

Lack of predict-method can be seen also from docs, so I guess this isn't the way to go with this. 从文档中也可以看到缺乏预测方法,所以我想这不是解决这个问题的方法。 http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.LatentDirichletAllocation.html http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.LatentDirichletAllocation.html

Now the question is: What is the way to go? 现在的问题是:要走的路是什么? How to use LatentDirichletAllocation (or similar) in Scikit-Learn Pipelines with Google Cloud ML Engine? 如何在Scikit-Learn管道中使用LatentDirichletAllocation (或类似)与Google Cloud ML Engine?

目前,管道的最后一个估算器必须实现predict方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Cloud ML引擎scikit学习预测概率'predict_proba()' - Google Cloud ML-engine scikit-learn prediction probability 'predict_proba()' 更新 scikit-learn:“SVC”对象没有属性“_probA”? - Updating scikit-learn: 'SVC' object has no attribute '_probA'? '线程'对象没有属性'_children'-django + scikit-learn - 'Thread' object has no attribute '_children' - django + scikit-learn scikit-learn中的对象没有属性,如何访问它? - Object has no attribute in scikit-learn, how can I access it? Scikit-learn: AttributeError: 'bool' object 没有属性 'any' - Scikit-learn: AttributeError: 'bool' object has no attribute 'any' 在Google Cloud ml引擎上调用本地预测或创建模型版本时,Scikit Learn模型导致错误 - Scikit Learn model results in error when calling local predict or creating model version on Google Cloud ml engine AttributeError: 'GridSearchCV' 对象在 scikit-learn 0.19.2 上没有属性 'cv_results_' - AttributeError: 'GridSearchCV' object has no attribute 'cv_results_' on scikit-learn 0.19.2 如何解决scikit-学习数字数据集的“ NoneType”对象没有属性“写入”错误? - How do I resolve 'NoneType' object has no attribute 'write' error with scikit-learn digits dataset? 在Google AI平台上使用Scikit学习获取预测时出现问题:“ numpy.ndarray”对象没有属性“ lower” - Problem getting predictions with Scikit-learn on Google AI Platform: 'numpy.ndarray' object has no attribute 'lower'" 导入问题 scikit-learn:模块“scipy”没有属性“_lib” - Issue importing scikit-learn: module 'scipy' has no attribute '_lib'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM