2
안녕하세요,이 텍스트 배열 분류기를 사용하여 배열을 반환하고 jsonresponse를 반환하고 싶지만 코드의 마지막 줄 나에게 오류를주는 '배열 (['자전거 ', DTYPE = 개체가) 아닌 JSON 직렬화'TypeError : 배열 ([ 'cycling'], dtype = object)이 JSON을 직렬화 할 수 없습니다.
쉽게 사용하여 수행 할 수있는list
객체에
numpy array
을 변환 할 필요가
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)
이 대신 나를 –
'pred'의 유형은 무엇입니까 답변을 제공하십시오 헌신? –
" ''pred = [ 'cycling'] 인 분류 자의 예측을 보유합니다. –