Input contains Nan with Tfidf vectorizer output











up vote
1
down vote

favorite












I've got a problem with the output of Tfidf Vectorizer and I've test many solutions given in other topics and nothing works.



I have a csv with two columns : one column test containing ... text and a column score.
And I want to be able to predict a new score based on a text I will be able to input.
I think the better solution is to use a linear regression based on tfidf analys on the text.



My code is the following :



datas = pandas.read_csv('Data/gucci-account- 
prediction.csv',delimiter=';')
datas['score'] = datas['retweets'] + datas['likes']
import re

def tokenizer(text):
if text:
result = re.findall('[a-z]{2,}', text.lower())
else:
result =
return result

X = datas['text'].values
y = datas['score'].values
vect = TfidfVectorizer(tokenizer=tokenizer,stop_words='english',dtype=np.float32)
X_train = vect.fit_transform(X)
lr = Ridge(alpha=1.0)
lr.fit(X_train,y)


And I have the following error : Input contains NaN, infinity or a value too large for dtype('float64').



I already verified and my dataframe ( before vectorization ) contains no nan value so I don't understand why my X matrix would contain any nan or infinite value.



Would you have a solution so it works ? Thank you










share|improve this question






















  • Please, add more information on the stack track (which line rises the error would be useful)
    – Julian Peller
    Nov 21 at 13:05















up vote
1
down vote

favorite












I've got a problem with the output of Tfidf Vectorizer and I've test many solutions given in other topics and nothing works.



I have a csv with two columns : one column test containing ... text and a column score.
And I want to be able to predict a new score based on a text I will be able to input.
I think the better solution is to use a linear regression based on tfidf analys on the text.



My code is the following :



datas = pandas.read_csv('Data/gucci-account- 
prediction.csv',delimiter=';')
datas['score'] = datas['retweets'] + datas['likes']
import re

def tokenizer(text):
if text:
result = re.findall('[a-z]{2,}', text.lower())
else:
result =
return result

X = datas['text'].values
y = datas['score'].values
vect = TfidfVectorizer(tokenizer=tokenizer,stop_words='english',dtype=np.float32)
X_train = vect.fit_transform(X)
lr = Ridge(alpha=1.0)
lr.fit(X_train,y)


And I have the following error : Input contains NaN, infinity or a value too large for dtype('float64').



I already verified and my dataframe ( before vectorization ) contains no nan value so I don't understand why my X matrix would contain any nan or infinite value.



Would you have a solution so it works ? Thank you










share|improve this question






















  • Please, add more information on the stack track (which line rises the error would be useful)
    – Julian Peller
    Nov 21 at 13:05













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I've got a problem with the output of Tfidf Vectorizer and I've test many solutions given in other topics and nothing works.



I have a csv with two columns : one column test containing ... text and a column score.
And I want to be able to predict a new score based on a text I will be able to input.
I think the better solution is to use a linear regression based on tfidf analys on the text.



My code is the following :



datas = pandas.read_csv('Data/gucci-account- 
prediction.csv',delimiter=';')
datas['score'] = datas['retweets'] + datas['likes']
import re

def tokenizer(text):
if text:
result = re.findall('[a-z]{2,}', text.lower())
else:
result =
return result

X = datas['text'].values
y = datas['score'].values
vect = TfidfVectorizer(tokenizer=tokenizer,stop_words='english',dtype=np.float32)
X_train = vect.fit_transform(X)
lr = Ridge(alpha=1.0)
lr.fit(X_train,y)


And I have the following error : Input contains NaN, infinity or a value too large for dtype('float64').



I already verified and my dataframe ( before vectorization ) contains no nan value so I don't understand why my X matrix would contain any nan or infinite value.



Would you have a solution so it works ? Thank you










share|improve this question













I've got a problem with the output of Tfidf Vectorizer and I've test many solutions given in other topics and nothing works.



I have a csv with two columns : one column test containing ... text and a column score.
And I want to be able to predict a new score based on a text I will be able to input.
I think the better solution is to use a linear regression based on tfidf analys on the text.



My code is the following :



datas = pandas.read_csv('Data/gucci-account- 
prediction.csv',delimiter=';')
datas['score'] = datas['retweets'] + datas['likes']
import re

def tokenizer(text):
if text:
result = re.findall('[a-z]{2,}', text.lower())
else:
result =
return result

X = datas['text'].values
y = datas['score'].values
vect = TfidfVectorizer(tokenizer=tokenizer,stop_words='english',dtype=np.float32)
X_train = vect.fit_transform(X)
lr = Ridge(alpha=1.0)
lr.fit(X_train,y)


And I have the following error : Input contains NaN, infinity or a value too large for dtype('float64').



I already verified and my dataframe ( before vectorization ) contains no nan value so I don't understand why my X matrix would contain any nan or infinite value.



Would you have a solution so it works ? Thank you







python regression vectorization






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 10:24









Pierre Ftn

2615




2615












  • Please, add more information on the stack track (which line rises the error would be useful)
    – Julian Peller
    Nov 21 at 13:05


















  • Please, add more information on the stack track (which line rises the error would be useful)
    – Julian Peller
    Nov 21 at 13:05
















Please, add more information on the stack track (which line rises the error would be useful)
– Julian Peller
Nov 21 at 13:05




Please, add more information on the stack track (which line rises the error would be useful)
– Julian Peller
Nov 21 at 13:05

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409968%2finput-contains-nan-with-tfidf-vectorizer-output%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409968%2finput-contains-nan-with-tfidf-vectorizer-output%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

Berounka

I want to find a topological embedding $f : X rightarrow Y$ and $g: Y rightarrow X$, yet $X$ is not...