-2

so please how can I resolve this kind of error, anyone's guide me please

X = df.iloc[:,:-2]
y = df.My_Labels 

from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score,confusion_matrix,classification_report
from sklearn.model_selection import KFold
import numpy as np
from sklearn.model_selection import GridSearchCV

log_class=LogisticRegression()
#grid={'C':10.0 **np.arange(-2,3),'penalty':['l1','l2'],'solver': [ 'lbfgs', 'liblinear']}
grid={'C':10.0 **np.arange(-2,3),'penalty': ['l1'], 'solver': [ 'lbfgs', 'liblinear', 'sag', 'saga'],'penalty': ['l2'], 'solver': ['newton-cg']} 
cv=KFold(n_splits=5,random_state=None,shuffle=False)

from sklearn.model_selection import train_test_split
X_train,X_test, y_train,y_test = train_test_split(X,y,test_size=0.3,random_state=10)

clf=GridSearchCV(log_class,grid,cv=cv,n_jobs=-1,scoring='f1_macro')
clf.fit(X_train.astype(str),y_train)

this is the error section, which I get when i run the above code for purely TEXT Classification

ValueError                                Traceback (most recent call last)
<ipython-input-18-4d99cebd483c> in <module>
     17 
     18 clf=GridSearchCV(log_class,grid,cv=cv,n_jobs=-1,scoring='f1_macro')
---> 19 clf.fit(X_train.astype(str),y_train)

ValueError: could not convert string to float: 'great kindle text sucks cant use calling feature phone im connected wifi makes great calls'

1 Answers1

1

It looks like you have text in your dataset, use Scikit-Learn's LabelEncoder to encode it into a numeric value. Use This Link if you don't know how to use LabelEncoder.

Looking at your error, I think you have some review column, If you don't want to LabelEncode it, use some NLP techniques and perform sentimental analysis and all.

Adarsh Wase
  • 1,727
  • 3
  • 12
  • 26