2017-11-07 13 views
2

こんにちは私はこれで使用したテキスト分類器を私に返していますが、jsonresponseあなたは簡単に使用して行うことができますlistオブジェクトにnumpy arrayを変換する必要が私にエラーを与えてコードの最後の行「の配列([」サイクリング「]、DTYPE =オブジェクト)、シリアライズJSONではありません」TypeError:配列(['cycling']、dtype = object)はJSONのシリアライズ可能ではありません

def classify_text(request): 
    if request.method == 'POST' and request.POST.get('text'): 
     test = [] 
     text = request.POST.get('text') 
     text = re.sub('[^a-zA-Z]', ' ', text) 
     text = text.lower() 
     text = text.split() 
     ps = PorterStemmer() 
     text = [ps.stem(word) for word in text if not word in set(stopwords.words('english'))] 
     text = ' '.join(text) 
     test.append(text) 

     pred = cv.transform(test).toarray() 
     pred = svm_model_linear.predict(pred) 
     return JsonResponse(pred, safe=False) 
+0

代わりに捧げる私はpred' 'の種類は何 –

+0

にお答え提供してください? –

+0

"'' pred = ['cycling']」という分類子の予測を保持しています –

答えて

1

numpy配列オブジェクトのメソッド.tolist()

pred_list = pred.tolist() 
return JsonResponse(pred_list, safe=False) 
関連する問題