Reputation: 31
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.
Upvotes: 0
Views: 12443
Reputation: 134
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
Upvotes: 1
Reputation: 1260
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.")
Upvotes: 1
Reputation: 791
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.
Upvotes: 1