作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想从我的函数返回两个不同的值如何重写我的代码以在两个不同的变量中返回这两个值。
所以我得到这个错误:
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)
最佳答案
在这一行中,
fea1, fea2 = build_feature_matrix_S(sentences)
feature_freq = pd.DataFrame(feature_matrix_freq.todense(), columns = vectorizer_freq.get_feature_names())
return feature_freq
feature_tfidf = pd.DataFrame(feature_matrix_tfidf.todense(), columns = vectorizer_tfidf.get_feature_names())
return feature_tfidf
关于python - 解包值过多时出现错误(预期2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60216073/
我是一名优秀的程序员,十分优秀!