簡體   English   中英

Cloud ML Engine和Scikit-Learn:'LatentDirichletAllocation'對象沒有屬性'predict'

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

我正在實施簡單的Scikit-Learn Pipeline以在Google Cloud ML Engine中執行LatentDirichletAllocation 目標是從新數據預測主題。 以下是生成管道的代碼:

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)

現在(如果我已經正確理解)預測測試數據的主題我可以運行:

pipeline.transform(test)

但是,在將管道上傳到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)

從文檔中也可以看到缺乏預測方法,所以我想這不是解決這個問題的方法。 http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.LatentDirichletAllocation.html

現在的問題是:要走的路是什么? 如何在Scikit-Learn管道中使用LatentDirichletAllocation (或類似)與Google Cloud ML Engine?

目前,管道的最后一個估算器必須實現predict方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM