'unorderable types: str() >= float()' error in Logistic Regression


Hey Authors,
I am getting an error while executing the LogisticRegression classifier. Please help. I have attached the code and error.

   >     #Logistic Regression
outcome_var = 'Loan_Status'
model = LogisticRegression()
predictor_var = ['Credit_History']
classification_model(model, train, predictor_var, outcome_var)

The part of error is follows:
> TypeError Traceback (most recent call last)

    <ipython-input-273-bb7bf01a98a4> in <module>()
          3 model = LogisticRegression()
          4 predictor_var = ['Credit_History']
    ----> 5 classification_model(model, train, predictor_var, outcome_var)

    <ipython-input-272-4e3d579b0cea> in classification_model(model, data, predictors, outcome)
         21         model.fit(train_predictors, train_target)
    ---> 23         error.append(model.score(data[predictors].iloc[test,:],data[outcome].iloc[test1]))

It seems the error is in the line where we append the error values to error list.


Hi @akki,

Make sure your predictor variable is of numerical data type. The library scikit-learn expects the target to be numerical in nature.

If the above solution does not work, I suggest you to break down this line,


into atomic code implementations (for example, an atomic part could be data[predictors]) and debug that line of code so that you can find the reason for the issue.


Thanks, @jalFaizy,
You solved my problem. The Credit_history attribute was still of type object. I just converted it to type float. Problem Solved.