精简用于情感分析的ML模型UG部署时出错

时间:2020-10-10 20:32:10

标签: python streamlit

有人可以帮助我找出此代码的问题吗? 当我运行此代码进行葡萄酒评论中的情感分析时。

%%writefile app1.py
import streamlit as st
import pandas as pd
import numpy as np
from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB

df = pd.read_table('/content/drive/My Drive/wine_review/file1.csv')
x = df['description'] # Message column as input
y = df['quality'] # Label column as output
st.title("Wine Review Classifier")
st.subheader('TFIFD Vectorizer')
st.write('This project is based on Naive Bayes Classifier')

text_model = Pipeline([('tfidf',TfidfVectorizer()),('model',MultinomialNB())])
text_model.fit(x,y)
message = st.text_area("Enter Text","Type Here ..")
op = text_model.predict([[message]])
if st.button("Predict"):
  st.title(op)

我正遇到此错误

KeyError: 'description'
Traceback:
File "/usr/local/lib/python3.6/dist-packages/streamlit/script_runner.py", line 324, in _run_script
    exec(code, module.__dict__)
File "/content/app1.py", line 9, in <module>
    x = df['description'] # Message column as input
File "/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py", line 2902, in __getitem__
    indexer = self.columns.get_loc(key)
File "/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py", line 2893, in get_loc
    raise KeyError(key) from err

0 个答案:

没有答案