from sklearn.feature_extraction.text import TfidfVectorizer
def average_tfidf(sents):
vec = TfidfVectorizer()
convert raw text to scipy sparse matrix (csr) of tfidf values
word_tfidf = vec.fit_transform(sents)
result = []
for sent in word_tfidf:
avg = sent.sum() / sent.getnnz()
result.append(avg)
return result
2. Run pylint on the file
### Current behavior
The `avg = sent.sum() / sent.getnnz()` produces four errors:
E: 22,14: Instance of 'float' has no 'sum' member (no-member)
E: 22,14: Instance of 'str' has no 'sum' member (no-member)
E: 22,27: Instance of 'float' has no 'getnnz' member (no-member)
E: 22,27: Instance of 'str' has no 'getnnz' member (no-member)
### Expected behavior
No errors should be produced.
### pylint --version output
No config file found, using default configuration
pylint 1.6.5,
astroid 1.4.9
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)]
Steps to reproduce
def average_tfidf(sents): vec = TfidfVectorizer()
convert raw text to scipy sparse matrix (csr) of tfidf values
E: 22,14: Instance of 'float' has no 'sum' member (no-member) E: 22,14: Instance of 'str' has no 'sum' member (no-member) E: 22,27: Instance of 'float' has no 'getnnz' member (no-member) E: 22,27: Instance of 'str' has no 'getnnz' member (no-member)
No config file found, using default configuration pylint 1.6.5, astroid 1.4.9 Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)]