Ошибка типа: "<" не поддерживается между экземплярами "str" и "int" для gridsearchcv
Я использую свою модель, используя sklearn
Pipeline
, но когда я запускаю GridSearchCV
чтобы получить мои лучшие параметры, я получаю ошибку.
Я использую преобразователь категории, чтобы указать мои числовые и категориальные переменные. Затем запустите трубопровод и, наконец, подгоните модель.
мой X
данные:
ID profit sales income gender color types
a 150.0 23 4500.60 male blue savings
b 100.0 15 300.00 female red investments
c 0.2 79 1500.29 male blue savings
и мой y
данные:
0 1
1 0
2 1
Мой код:
#import libraries
from sklearn.preprocessing import OneHotEncoder
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.metrics import accuracy_score, classification_report`
#ColumnTransformer
num_features = ["profit", "sales", "income "]
cat_features = ["gender", "color"]
#preprocessor
preprocessor = ColumnTransformer([
("numerical", "passthrough", num_features),
("categorical", OneHotEncoder(sparse=False, handle_unknown="ignore"), cat_features),
])
#model pipeline
lr_model = Pipeline([
("preprocessor", preprocessor),
("model", LogisticRegression(class_weight="balanced", solver="liblinear", random_state=42)),
])
# Train/Valid
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, test_size=.3)
#get parameters
gs = GridSearchCV(
lr_model,
{"model__C": [1, 1.3, 1.5]},
n_jobs=-1,
cv=5,
scoring="accuracy")
gs.fit(X_train, y_train)
Я получаю ошибку ниже:
_RemoteTraceback Traceback (most recent call last) _RemoteTraceback:
TypeError: '<' not supported between instances of 'str' and 'int'