Unable to convert string to float

Asked

Viewed 83 times

0

I am trying to run a classification model and I am getting the feedback that it is not possible to convert string to float in the predictive variables. When I give a dtypes I see that all variables are float or Int. I did the whole exploratory analysis process, pre-processing: all variables are numerical, I scaled, I did variable selection with logistic regression and recursive elimination. Follows code:

from sklearn import tree
x_treino = ['a', 'b', 'c', 'd', 'e']
y_treino = ['tt']
x_teste = ['a', 'b', 'c', 'd', 'e'] 

# Criando o objeto logistic regression
model = LogisticRegression()

# Criando o objeto tree para classificação
model = tree.DecisionTreeClassifier()

# Treinando o modelo com dados de treino e checando o score
model.fit(x_treino, y_treino)
model.score(x_treino, y_treino)

# Previsões
valores_previstos = model.predict(x_teste)

You can help me how to solve this. Is there any way to look line by line at these variables to see if there are any characters in them?? Thanks

  • Hello guys. I couldn’t solve this problem, so I chose to do it another way using sklearn’s train_test_split package. I created manually the division of test and training data. Done this I ran the Machine Learning models smoothly.

  • Good afternoon, Edi. I believe you meant "model.score(x_test, y_test)" instead of "model.score(x_workout, y_workout)" in your code, correct?

1 answer

1

To check whether they are empty or not, Voce can do a validation with if.

for v in x_treino: # "Para cada valor em x_treino"
    if v == None:  # Se o valor for None (nada)
        print('Valor vazio no x_treino')
        break
    else:
        model = LogisticRegression()

Likewise, I was able to use != to validate.
I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.