Python 类型错误:'<';在';str';和';int';在网格搜索期间

Python 类型错误:'<';在';str';和';int';在网格搜索期间,python,scikit-learn,Python,Scikit Learn,我正在我的数据集上尝试网格搜索。但我得到了错误,但在使用cross_val_分数进行交叉验证时没有发生错误 我导入了这些库。我是谷歌colab笔记本 import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from sklearn.model_selection import train_test_split, cross_val_score from sklea

我正在我的数据集上尝试网格搜索。但我得到了错误,但在使用cross_val_分数进行交叉验证时没有发生错误

我导入了这些库。我是谷歌colab笔记本

import numpy as np
import pandas as pd

import matplotlib.pyplot as plt
import seaborn as sns

from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.preprocessing import StandardScaler

from sklearn import linear_model
from sklearn.model_selection import GridSearchCV, RandomizedSearchCV

import warnings
warnings.filterwarnings('ignore')

np.random.seed(27)
导入数据集

!wget -O 2010gcn.csv https://raw.githubusercontent.com/pranavn91/blockchain/master/2010gcn.csv
!wget -O tx2010partvertices.csv https://raw.githubusercontent.com/pranavn91/blockchain/master/tx2010partvertices.csv

train1 = pd.read_csv('2010gcn.csv')
train3 = pd.read_csv('tx2010partvertices.csv')
train1.rename(columns={'Unnamed: 0':'index'}, inplace=True)
train1['index'] = train1['index'] + 1
train3.rename(columns={'Unnamed: 0':'index'}, inplace=True)
results = pd.merge(train3, train1, on='index', how='inner')

# split data into X and y
X = results.iloc[:,2:18]
Y = results['label']
seed = 7
test_size = 0.2
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=test_size, random_state=seed)
然后我试了一下

penalty = ['l1', 'l2']
C = [0.0001, 0.001, 0.01]
class_weight = [{1:0.5, 0:0.5}, {1:0.4, 0:0.6}]
solver = ['liblinear', 'saga']

param_grid = dict(penalty=penalty,
                  C=C,
                  class_weight=class_weight,
                  solver=solver)

grid = GridSearchCV(estimator=logistic, param_grid=param_grid, scoring='accuracy', verbose=1, n_jobs=-1)
grid_result = grid.fit(X_train, y_train)

print('Best Score: ', grid_result.best_score_)
print('Best Params: ', grid_result.best_params_)
我得到的错误是

Fitting 5 folds for each of 128 candidates, totalling 640 fits

[Parallel(n_jobs=-1)]: Using backend LokyBackend with 2 concurrent workers.
[Parallel(n_jobs=-1)]: Done 164 tasks      | elapsed:    4.6s
[Parallel(n_jobs=-1)]: Done 640 out of 640 | elapsed:   17.3s finished

---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
     60     try:
---> 61         return bound(*args, **kwds)
     62     except TypeError:

TypeError: '<' not supported between instances of 'str' and 'int'


During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)

7 frames

<__array_function__ internals> in searchsorted(*args, **kwargs)

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)
     45     except AttributeError:
     46         wrap = None
---> 47     result = getattr(asarray(obj), method)(*args, **kwds)
     48     if wrap:
     49         if not isinstance(result, mu.ndarray):

TypeError: '<' not supported between instances of 'str' and 'int'
为128名候选人中的每一人进行5次试衣,总共640次试衣
[并行(n_jobs=-1)]:使用后端LokyBackend和2个并发工作线程。
[并行(n_作业=-1)]:完成164项任务|耗时:4.6秒
[并行(n_作业=-1)]:完成640个作业中的640个已完成:完成17.3s
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
/wrapfunc中的usr/local/lib/python3.6/dist-packages/numpy/core/fromneric.py(obj,method,*args,**kwds)
60次尝试:
--->61返回边界(*args,**kwds)
62除类型错误外:
TypeError:'