2
$\begingroup$

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/>
$\endgroup$
4
  • $\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, 2019 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, 2019 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, 2019 at 18:52
  • $\begingroup$ Okay..Thank you. $\endgroup$
    – venu
    Dec 29, 2019 at 18:53

1 Answer 1

1
$\begingroup$

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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