2017-02-01 13 views
0

モジュールが訓練されていないエラーを受け取りました。しかし、私はモジュールに問題がありますMonkeyLearn - モジュールが訓練されたエラーではありません

from monkeylearn import MonkeyLearn 

# Use the API key from your account 
ml = MonkeyLearn('211893df48b') 

# Create a new classifier 
res = ml.classifiers.create('Test Classifier') 

# Get the id of the new module 
module_id = res.result['classifier']['hashed_id'] 

# Get the id of the root node 
res = ml.classifiers.detail(module_id) 
root_id = res.result['sandbox_categories'][0]['id'] 

# Create two new categories on the root node 
res = ml.classifiers.categories.create(module_id, 'Negative', root_id) 
negative_id = res.result['category']['id'] 
res = ml.classifiers.categories.create(module_id, 'Positive', root_id) 
positive_id = res.result['category']['id'] 

# Now let's upload some samples 
samples = [('The movie was terrible, I hated it.', negative_id), ('I love this movie, I want to watch it again!', positive_id)] 
res = ml.classifiers.upload_samples(module_id, samples) 

# Now let's train the module! 
res = ml.classifiers.train(module_id) 

# Classify some texts 
res = ml.classifiers.classify(module_id, ['I love the movie', 'I hate the movie'], sandbox=True) 
print res.result 

Traceback (most recent call last): File "monkey_learn.py", line 30, in res = ml.classifiers.classify(module_id, ['I love the movie', 'I hate the movie'], sandbox=True) File "build/bdist.linux-x86_64/egg/monkeylearn/classification.py", line 67, in classify File "build/bdist.linux-x86_64/egg/monkeylearn/utils.py", line 101, in handle_errors monkeylearn.exceptions.MonkeyLearnException: Error: "The module is not trained. You have to train it before using the api."

答えて

0

問題は、モデルのトレーニングが終了する前に、新しいテキストを分類しようとしているようです。分類を使用する前に少し待ってください(トレーニングを完了するのに十分な時間を与えてください)。

0

サンプルコードでトレーニングセットを作成しました。 MonkeyLearnで始めるために、私たちはpublicモジュールを使うことができます。パブリックモジュールは、MonkeyLearnコミュニティによって作成されたあらかじめ構築されたモジュールです。

from monkeylearn import MonkeyLearn 

ml = MonkeyLearn('211893df48b') 
text_list = ["This is a text to test your classifier", "This is some more text"] 
# English Tweets Sentiment Analysis 
module_id = 'cl_qkjxv9Ly' 
res = ml.classifiers.classify(module_id, text_list, sandbox=True) 
print res.result 
関連する問題