Streamlit ValueError: Истинное значение Серии неоднозначно. Используйте a.empty, a.bool(), a.item(), a.any() или a.all()

Я пытаюсь подогнать свою модель в приложении Streamlit.io, но получаю указанную выше ошибку Value-Error. Но он не дает такой же ошибки на Jupyter Notebook. Пожалуйста, любой лучший подход очень поможет.

Я использую Env на основе Conda в моем VScode, поэтому версия Pandas, Sklearn и Python, которую я использую в VScode, такая же, как и в Jupyter Notebook.

 
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
File "c:\users\8470p\anaconda3\lib\site-packages\streamlit\ScriptRunner.py", line 311, in _run_script exec(code, module.__dict__)
File "C:\Users\8470p\app2.py", line 122, in  bow_transformer = CountVectorizer(analyzer=text_process).fit(messages['message'])
File "c:\users\8470p\anaconda3\lib\site-packages\sklearn\feature_extraction\text.py", line 1024, in fit self.fit_transform(raw_documents)
File "c:\users\8470p\anaconda3\lib\site-packages\sklearn\feature_extraction\text.py", line 1058, in fit_transform self.fixed_vocabulary_)
File "c:\users\8470p\anaconda3\lib\site-packages\sklearn\feature_extraction\text.py", line 962, in _count_vocab analyze = self.build_analyzer()
File "c:\users\8470p\anaconda3\lib\site-packages\sklearn\feature_extraction\text.py", line 339, in build_analyzer if self.analyzer == 'char':
File "c:\users\8470p\anaconda3\lib\site-packages\pandas\core\generic.py", line 1555, in __nonzero__ self.__class__.__name__ 

введите код сюда



    from sklearn.feature_extraction.text import CountVectorizer
    from sklearn.model_selection import train_test_split
    from sklearn.pipeline import Pipeline
    from sklearn.metrics import classification_report
    from sklearn.feature_extraction.text import TfidfTransformer
    from sklearn.naive_bayes import MultinomialNB


    msg_train, msg_test, label_train, label_test = train_test_split(messages['message'], messages['label'], test_size=0.2)


    @st.cache(suppress_st_warning = True)
    def Pipeline_Processing(a = msg_train, b = msg_test, c = label_train, d =label_test):
        pipeline = Pipeline([
        ('bow', CountVectorizer(analyzer=text_process)),  # strings to token integer counts
        ('tfidf', TfidfTransformer()),  # integer counts to weighted TF-IDF scores
        ('classifier', MultinomialNB()),  # train on TF-IDF vectors w/ Naive Bayes classifier
         ])

        pipeline.fit(msg_train,label_train)

        predictions = pipeline.predict(msg_test)

        return predictions

    Pipeline_Processing()


    if __name__ == "__main__":
        main()

0 ответов

Другие вопросы по тегам