When I apply GridSearchCV to my model Logistic Regression, it's continuously throwing below error. I understand that it's trying to convert string to float. But that's was my data. So how can I convert my x value to float? Can any please hep me with this issue. Thank you.

Error: could not convert string to float: 'great im readi go home'

Sample data

Airline_sentiment text

0     said <br/>
1     plu youv ad commerci experi tacki <br/>
2     didnt today must mean need take anoth trip<br/>

penalty = ['l1', 'l2']<br/>
C = np.logspace(0, 4, 10)<br/>
hyperparameters = dict(C=C, penalty=penalty)<br/>
gs = **GridSearchCV**(lr,hyperparameters,cv=5)<br/>
  • $\begingroup$ Yes you can apply it, refer the docs please.; ML models can only take in "number or numeral representations" of the same, they generally don't take raw strings as such directly, so go for a tf-idf+log reg baseline! $\endgroup$ – Aditya Dec 29 '19 at 18:11
  • $\begingroup$ Do you mean, instead of a string of do I need to apply tfidf x matrix value .? $\endgroup$ – venu Dec 29 '19 at 18:51
  • $\begingroup$ Yep, I would recommend checking out scikit learn examples first.. They are very well written with reusable code blocks to get you started. Your error code is very clear imho $\endgroup$ – Aditya Dec 29 '19 at 18:52
  • $\begingroup$ Okay..Thank you. $\endgroup$ – venu Dec 29 '19 at 18:53

I believe that the first thing you should do is to convert your data to a numeric type.

Maybe this starter tutorial can help you https://towardsdatascience.com/introduction-to-natural-language-processing-nlp-323cc007df3d

  • $\begingroup$ Thank you, I fixed it. $\endgroup$ – venu Dec 31 '19 at 14:49
  • $\begingroup$ then upvote please :) $\endgroup$ – Carlos Mougan Dec 31 '19 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.