Python 3.x GridSearchCV和RandomizedSearchCV(sklearn):TypeError:uuu调用uuu()缺少1个必需的位置参数:';是真的';
我尝试使用Python 3.x GridSearchCV和RandomizedSearchCV(sklearn):TypeError:uuu调用uuu()缺少1个必需的位置参数:';是真的';,python-3.x,scikit-learn,grid-search,Python 3.x,Scikit Learn,Grid Search,我尝试使用GridSearchCV和RandomizedSearchCV为两种无监督学习算法(用于新颖性检测)找到最佳参数,即OneClassSVM和LocalOutlierFactor 下面是我编写的函数(对此进行了修改): 要测试上述功能,我有以下代码: X, W = train_test_split(all_data, test_size=0.2, random_state=42) clf_lof = LocalOutlierFactor(novelty=True, contaminati
GridSearchCV
和RandomizedSearchCV
为两种无监督学习算法(用于新颖性检测)找到最佳参数,即OneClassSVM
和LocalOutlierFactor
下面是我编写的函数(对此进行了修改):
要测试上述功能,我有以下代码:
X, W = train_test_split(all_data, test_size=0.2, random_state=42)
clf_lof = LocalOutlierFactor(novelty=True, contamination='auto')
lof_param_dist_rand = {'n_neighbors': np.arange(6, 101, 1), 'leaf_size':
np.arange(30, 101, 10)}
lof_param_grid_exhaustive = {'n_neighbors': np.arange(6, 101, 1),
'leaf_size': np.arange(30, 101, 10)}
gridsearch(clf=clf_lof, param_dist_rand=lof_param_dist_rand,
param_grid_exhaustive=lof_param_grid_exhaustive, X=X)
clf_svm = svm.OneClassSVM()
svm_param_dist_rand = {'nu': np.arange(0, 1.1, 0.01), 'kernel': ['rbf',
'linear','poly','sigmoid'], 'degree': np.arange(0, 7,
1), 'gamma': scipy.stats.expon(scale=.1),}
svm_param_grid_exhaustive = {'nu': np.arange(0, 1.1, 0.01), 'kernel':
['rbf', 'linear','poly','sigmoid'], 'degree':
np.arange(0, 7, 1), 'gamma': 0.25}
gridsearch(clf=clf_svm, param_dist_rand=svm_param_dist_rand,
param_grid_exhaustive=svm_param_grid_exhaustive, X=X)
最初,我没有为两种GridSearch
方法设置scoring
参数,我得到了以下错误:
TypeError: If no scoring is specified, the estimator passed should have a 'score' method.
TypeError: __call__() missing 1 required positional argument: 'y_true'
然后我添加了scoring='accurity'
,因为我想使用测试精度来判断不同型号配置的性能。现在我得到了这个错误:
TypeError: If no scoring is specified, the estimator passed should have a 'score' method.
TypeError: __call__() missing 1 required positional argument: 'y_true'
我没有标签,因为我有来自一个类的数据,而没有来自计数器类的数据,所以我不知道如何处理这个错误。此外,我还研究了本文中的建议,但这对我没有帮助。任何帮助都将不胜感激
编辑:
根据@FChm提供样本数据的建议,请查找样本.csv
数据文件。文件的简短说明:
由四列特征(PCA生成)组成,我将这些特征输入到我的模型中 如果您提供指向某些示例数据的链接,人们可能更愿意提供帮助。@FChm我添加了一个包含示例数据的文件。谢谢你的建议。我认为下面这个问题的讨论可能会有用:简而言之,在没有y_true的情况下使用GridSearchCV不是一个非常直观的选择,因为你基本上不再需要任何交叉验证。谢谢@MaximeKan。我还没有找到在没有CV的情况下使用GridSearch的选项。仍然在搜索。这里有一个建议:但它不再适用,我尝试了。如果您提供指向某些示例数据的链接,人们可能会更愿意提供帮助。@FChm我已添加了一个包含示例数据的文件。谢谢你的建议。我认为下面这个问题的讨论可能会有用:简而言之,在没有y_true的情况下使用GridSearchCV不是一个非常直观的选择,因为你基本上不再需要任何交叉验证。谢谢@MaximeKan。我还没有找到在没有CV的情况下使用GridSearch的选项。但仍在寻找。这里有一个建议:但它不再适用,我试过了。