python - 使用 sklearn 管道时出现 ValueError:数组不得包含 infs 或 NaN
问题描述
您好我正在使用 sklearn 管道来实现 tfidf 矢量化和随机福雷斯特。使用带有 khold 交叉验证测试的 BayesSearch 进行超参数调整。
交叉验证的前几轮看起来找到了,但后来我得到了一个错误clf_search.fit(X, y)
ValueError: array must not contain infs or NaNs
. 我的数据集中没有 infs 或 NaNs 值。
这是我的代码
# pipeline
pipeline = Pipeline(steps=[
('tfidf', TfidfVectorizer(ngram_range=(2,3), norm=None))
, ("clf", RandomForestClassifier())
])
# parameters
n_estimators = [int(x) for x in np.linspace(start = 200, stop = 2000, num = 10)]
max_features = ['auto', 'log2']
max_depth = [int(x) for x in np.linspace(10, 100, num = 11)]
max_depth.append(None)
min_samples_split = [2, 5, 10]
min_samples_leaf = [1, 2, 4]
bootstrap = [True, False]
# Create the random grid
random_grid = {'clf__n_estimators': n_estimators
, 'clf__max_features': max_features
, 'clf__max_depth': max_depth
, 'clf__min_samples_split': min_samples_split
, 'clf__min_samples_leaf': min_samples_leaf
, 'clf__bootstrap': bootstrap}
# Search
clf_search = BayesSearchCV(pipeline
, search_spaces = random_grid
, n_iter = 100
, cv = 5
, verbose=2
, random_state=42
, n_jobs = -1)
clf_search.fit(X, y)
解决方案
推荐阅读
- d3.js - d3.js - 使用 d3 实现 git 分支节点布局自动化
- c# - 将文本文件中的二进制数据转换为文本格式
- c++ - 原型匹配函数时出现未定义符号错误
- php - 向电子邮件八达通发送 PUT 请求时出现“INVALID_PARAMETERS”错误响应
- python - Python subprocess.Popen 方法不执行“start chrome”命令
- django-forms - 如何在 Wagtail 的自定义字段中检索 Django 模板中的附加字段名称?
- sitecore - Sitecore 9.3 发布问题
- python - Python - Django 提交表单时提交按钮不起作用
- php - 如何捕获 PHP 7 和 8 中的致命错误?
- javascript - 使用jquery获取带有国家代码的国际电话输入值