Я хочу вернуть два разных значения из моей функции, как я могу переписать свой код, чтобы вернуть два в двух разных переменных.
Итак, я получаю эту ошибку:
Traceback (most recent call last):
File "features.py", line 300, in <module>
fea1, fea2 = build_feature_matrix_S(sentences)
ValueError: too many values to unpack (expected 2)
здесь код
def build_feature_matrix_S(documents):
feature_type = ['frequency','tfdif']
#feature_type = feature_type.lower().strip()
for f in feature_type:
if feature_type == 'frequency':
vectorizer_freq = CountVectorizer(tokenizer = tokenize_lemmatize_spacy, binary=False, min_df=5, ngram_range=(1, 2))
feature_matrix_freq = vectorizer_freq.fit_transform(documents)
feature_freq = pd.DataFrame(feature_matrix_freq.todense(), columns = vectorizer_freq.get_feature_names())
return feature_freq
else:
vectorizer_tfidf = TfidfVectorizer(tokenizer = tokenize_lemmatize_spacy, min_df=5, ngram_range=(1, 2))
feature_matrix_tfidf = vectorizer_tfidf.fit_transform(documents)
feature_tfidf = pd.DataFrame(feature_matrix_tfidf.todense(), columns = vectorizer_tfidf.get_feature_names())
return feature_tfidf
fea1, fea2 = build_feature_matrix_S(sentences)
print(fea1, fea2)