0

While implementing Logistic Regression on some bank data I faced an error ValueError: could not convert string to float: 'no'. Here is the code I have tried until now.

bank_full=pd.read_csv("/home/bilal/Desktop/linkedinlearning/recommendation-system-python/bank/bank-full.csv")
bank_full.head()

X=bank_full.iloc[:,:37].values 
y=bank_full.iloc[:,:18].values
Logreg=LogisticRegression()
Logreg.fit(X,y) #ERROR HERE.

enter image description here

1
  • 1
    Please paste the error message as text, so it's more readable and searchable. Commented Jul 13, 2020 at 7:15

3 Answers 3

1

It sounds like you have a value in your data that is supposed to be a number but is actually a string called 'no'. Perhaps give the data a quick check before you convert it from strings to floats.

Sign up to request clarification or add additional context in comments.

Comments

1

This error means that there are some lines in your data which do not contain valid float data, specifically a line which contains the string no.

I would suggest using a for loop to loop over your data to check which lines are the ones causing the error, as follows:

for i in data:
    try:
        i = float(i)
        print(i)
    except:
        print("Invalid data.")

Comments

1

If you're using the Bank Marketing Data Set, the target(y) values are encoded as 'yes' and 'no'. You could do something like this:

bank.loc[bank.y == "yes", 'subscribe'] = 1
bank.loc[bank.y == "no", 'subscribe'] = 0

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.