- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
希望能帮到你
我一直在尝试使用 scikit learn 中的随机搜索功能来调整我的随机森林模型。
如下,我给出了几个最大深度和几个叶子样本的选项。
# Create a based model
model = RandomForestClassifier()
# Instantiate the random search model
best = RandomizedSearchCV(model, {
'bootstrap': [True, False],
'max_depth': [80, 90, 100, 110],
'min_samples_leaf': [3, 4, 5]
}, cv=5, return_train_score=True, iid=True, n_iter = 4)
best.fit(train_features, train_labels.ravel())
print(best.best_score_)
print(best)
但是当我运行这个时,我得到以下结果,其中最大深度和每个叶子的最小样本设置为不在我的数组中的值。
我在这里做错了什么?
RandomizedSearchCV(cv=5, error_score='raise',
estimator=RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
**max_depth=None**, max_features='auto', max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
**min_samples_leaf=1**, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,
oob_score=False, random_state=None, verbose=0,
warm_start=False),
fit_params=None, iid=True, n_iter=4, n_jobs=1,
param_distributions={'bootstrap': [True, False], 'max_depth': [80, 90, 100, 110], 'min_samples_leaf': [3, 4, 5]},
pre_dispatch='2*n_jobs', random_state=None, refit=True,
return_train_score=True, scoring=None, verbose=0)
最佳答案
您为 RandomizedSearchCV
对象选择的名称 best
实际上用词不当:best
将包含全部参数,不仅是最好的参数,还包括 RF 模型的参数,其中一些参数在随机搜索过程中实际上会被覆盖。因此,print(best)
正如预期的那样,准确地给出了这个结果,即所有参数值,包括 RF 的默认值,这些值实际上不会在这里使用(它们将被参数
中的值覆盖)。
你应该问的是
print(best.best_params_)
找到最佳参数,
print(best.best_estimator_)
对于具有找到的最佳参数的整个射频模型。
这是一个使用虹膜数据的可重现示例(名称为 clf
而不是 best
):
from sklearn.ensemble import RandomForestClassifier
from sklearn import datasets
from sklearn.model_selection import RandomizedSearchCV
iris = datasets.load_iris()
parameters = {
'bootstrap': [True, False],
'max_depth': [80, 90, 100, 110],
'min_samples_leaf': [3, 4, 5]
}
model = RandomForestClassifier()
clf = RandomizedSearchCV(model, parameters, cv=5, return_train_score=True, iid=True, n_iter = 4)
clf.fit(iris.data, iris.target)
请注意,即使没有任何 print
请求,最后一个 fit
命令的默认控制台输出也将是:
RandomizedSearchCV(cv=5, error_score='raise-deprecating',
estimator=RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
max_depth=None, max_features='auto', max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_estimators='warn', n_jobs=None,
oob_score=False, random_state=None, verbose=0,
warm_start=False),
fit_params=None, iid=True, n_iter=4, n_jobs=None,
param_distributions={'max_depth': [80, 90, 100, 110], 'bootstrap': [True, False], 'min_samples_leaf': [3, 4, 5]},
pre_dispatch='2*n_jobs', random_state=None, refit=True,
return_train_score=True, scoring=None, verbose=0)
这与您报告的基本相同(我在上面已经解释过):只是您的 RF 模型的默认值(因为您没有为 model
指定任何参数),加上参数
网格。要选择特定的参数集,您应该使用
clf.best_params_
# {'bootstrap': True, 'max_depth': 90, 'min_samples_leaf': 5}
并询问clf.best_estimator_
确实确认我们得到了具有这些精确参数值的RF:
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
max_depth=90, max_features='auto', max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=5, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=None,
oob_score=False, random_state=None, verbose=0,
warm_start=False)
关于python - 不应用所选参数的随机搜索 CV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56176338/
我到处都找了很多,找不到我的问题的答案。我试图从这个线程复制一个文本检测软件(Extracting text OpenCV)但是在代码的末尾有一条消息错误说没有匹配的矩形,即使我已经在上面绘制了一个并
我已经彻底搜索过,但没有找到直接的答案。 将 opencv 矩阵 (cv::Mat) 作为参数传递给函数,我们传递的是智能指针。我们对函数内部的输入矩阵所做的任何更改也会改变函数范围之外的矩阵。 我读
在我的应用程序中,我有一个通过引用接收 cv::Mat 对象的函数。这是函数的声明: void getChains(cv::Mat &img,std::vector &chains,cv::
我正在使用 Qt 编写一个 GUI 程序,并使用 OpenCV 进行一些视频处理。我在主 GUI 线程的标签中显示 OpenCV 进程(在单独的线程中)的结果。 我遇到的问题是 cv::waitKey
Mat a = (Mat_(3,3) = 2 int dims; //! the number of rows and columns or (-1, -1) when the arr
我尝试运行下面的代码,但出现错误。我正在为名为“Mat::at”的 OpenCV 函数创建一个包装器,并尝试使用“G++”将其编译为 Ubuntu Trusty 上的“.so”。我在下面列出了“.cp
我在 C# 中使用 EmguCV,当我想从网络摄像头抓取帧时遇到问题,语句中出现红色下划线: imgOrg = capturecam.QueryFrame(); error: Cannot impli
我正在尝试从另外两个矩阵生成一个 cv::Mat C,以便获得第三个矩阵,该矩阵由通过组合矩阵 A 和 B 的一维点生成的二维点构成。 我的问题是,我尝试的所有操作都只是连接矩阵,并没有真正将每个点与
我用 cv.imread在 python 中读取 png 文件。然后当我使用 cv.imwrite立即保存图像的功能我然后发现图像中的颜色略有变化。我正在尝试在此图像上执行字符识别,而 OCR 在 p
我尝试将 cv::bitwise_not 转换为 double 值的 cv::Mat 矩阵。我申请了 cv::bitwise_not(img, imgtemp); img是0和1的CV_64F数据。但
我正在尝试使用函数 cv.glmnet 找到最佳的 lambda(使用 RIDGE 回归)以预测某些对象的归属类别。所以我使用的代码是: CVGLM<-cv.glmnet(x,y,nfolds=34,
我有这个方法: static void WriteMatVect(const std::string& filename, const std::vector& mats); ... void Fil
下面的转换是我想要做的。 对于源图像中的每个图 block ,我知道每个角的坐标,并且我知道输出图像中每个对应角的坐标,所以我可以调用 cvWarpPerspective 扭曲每个图 block ,然
我必须在C++ / CLI中的托管和非托管代码中都使用OpenCV。 我正在尝试在托管代码中使用Emgu CV来包装OpenCV对象,但是在进行转换时遇到了麻烦。 我该怎么做: Emgu::CV::M
我正在尝试在 cv::Mat 中使用 CV_32FC4,以便它存储 RGBA32 图像。但是当我使用 cv::imwrite 将其保存为 png 文件时,结果文件始终是一个空图像。 例如,我创建了这样
无法在 VS 2017 中设置 OpenCV。我做错了什么?是的,我已将所有其他帖子设为红色。 代码: #include "opencv2/highgui/highgui.hpp" u
我有两个(相同大小,相同类型)cv:Mat 让我们称它们为 A,B。我还有另一个 cv::Mat,它是一个掩码(0 和 1 值或其他值,0 和 255 也适用)让我们称它为 M。 我需要构造一个新的
使用 OpenCV 中实现的 Scalar 类,我不明白这段代码有什么区别: Mat test; test = Scalar::all(0); 还有这个: Mat test = Scalar::all
我对这行代码感到困惑: cv::Mat_::iterator 我知道 Mat_ 属于 cv 命名空间和 vec3b 也。但是之后的最后一个 :: 操作符和 iterator 让我感到困惑!它也属于 c
我想优雅地将 Mat 转换为 Vec3f。目前我是这样做的: Mat line; Vec3f ln; ln[0] = line.
我是一名优秀的程序员,十分优秀!