- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 scikit-learn 的 GaussianMixture 函数,我必须执行模型选择。
我想通过使用 GridSearchCV 来做到这一点,我想使用 BIC 和 AIC 进行选择。
这两个值都在 GaussianMixture() 中实现,但我不知道如何将它们插入到我的自定义计分器的定义中,因为函数
make_scorer(score_func, greater_is_better=True, needs_proba=False, needs_threshold=False, **kwargs)
score_func(y, y_pred, **kwargs)
最佳答案
使用 BIC/AIC 是使用交叉验证的替代方法。 GridSearchCV
使用交叉验证选择模型。要使用 BIC/AIC 执行模型选择,我们必须做一些不同的事情。让我们举一个例子,我们从两个高斯中生成样本,然后尝试使用 scikit-learn 拟合它们。
import numpy as np
X1 = np.random.multivariate_normal([0.,0.],[[1.,0.],[0.,1.]],10000)
X2 = np.random.multivariate_normal([10.,10.],[[1.,0.],[0.,1.]],10000)
X = np.vstack((X1,X2))
np.random.shuffle(X)
from sklearn.mixture import GaussianMixture
from sklearn.model_selection import GridSearchCV
import matplotlib.pyplot as plt
#check 1->4 components
tuned_parameters = {'n_components': np.array([1,2,3,4])}
#construct grid search object that uses 2 fold cross validation
clf = GridSearchCV(GaussianMixture(),tuned_parameters,cv=2)
#fit the data
clf.fit(X)
#plot the number of Gaussians against their rank
plt.scatter(clf.cv_results_['param_n_components'],\
clf.cv_results_['rank_test_score'])
bic = np.zeros(4)
n = np.arange(1,5)
models = []
#loop through each number of Gaussians and compute the BIC, and save the model
for i,j in enumerate(n):
#create mixture model with j components
gmm = GaussianMixture(n_components=j)
#fit it to the data
gmm.fit(X)
#compute the BIC for this model
bic[i] = gmm.bic(X)
#add the best-fit model with j components to the list of models
models.append(gmm)
plt.plot(n,bic)
关于python - 使用 GridSearch 选择 GaussianMixture 的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39920862/
尝试在组合了几个分类器的投票集合上运行网格搜索。我在运行代码时不断遇到同样的错误 ValueError: Invalid parameter n_estimator for estimator Gra
我正在做线性回归建模,我使用网格搜索来选择最佳参数。下面是我为这项工作遵循的 python 步骤,但出现错误(ValueError:估算器 LinearRegression(copy_X=True,f
我需要对维度 (5000, 26421) 的数据集执行内核 pca 以获得较低维度的表示。为了选择分量的数量(比如 k)参数,我正在执行数据的减少和对原始空间的重建,并获得不同 k 值的重建数据和原始
使用 gridsearch 调整超参数会导致过度拟合。 训练误差肯定很低,但测试误差很高。不能调整超参数来降低测试误差吗? def custom_wmae(actual_values, predict
我使用不同的数据集训练不同的分类器,我需要了解如何正确衡量分类器的有效性。 这是我的代码: iris = load_iris() param_grid = { 'criterion': ['g
在我的数据集上使用 GridSearchCV 后,我想提取所有最佳参数。 from sklearn.tree import DecisionTreeClassifier params_grid = {
我已经设置了一个 GridSearchCV 并有一组参数,我会找到最佳的参数组合。我的 GridSearch 总共包含 12 个候选模型。 但是,我也有兴趣查看所有 12 个的准确度分数,而不仅仅是最
from keras.wrappers.scikit_learn import KerasClassifier from sklearn.model_selection import GridSear
我是机器学习领域的新手,我开始参加 Kaggle 比赛以获得一些实践经验。我正在参加知识竞赛 CIFAR 10- 图像中的对象识别,你必须在 10 类中对数千张图像进行分类,我使用的所有数据都可以在那
我使用 grid_search 来找到参数的最佳组合,并制作了一个绘图来查看参数更改时分数如何变化。当我运行 gs_clf.best_params_ 时,我将其作为参数的最佳组合:{'learning
model.fit(train_data, y=label_data, eval_set=eval_dataset) eval_dataset = Pool(val_data, val_labels)
我创建了一个简单的脚本来对随机森林分类器应用网格搜索,虽然我过去使用过它,但它现在似乎被破坏了,我找不到原因。 from sklearn.ensemble import RandomForestCla
我正在尝试使用一些自定义转换器优化 scikit-learn 管道中的超参数,但我不断收到错误消息: from sklearn.model_selection import TimeSeriesSpl
我有一个带有 TfidVectorizer 和 OneVsRestClassifier(SGDClassifier) 的管道。这是我要执行的 gridSearch 的参数: parameters =
我正在尝试使用 GridSearch Scala 中的 api H2O 。我找到了this文档显示了在 R 和 Python 中做什么,但 Java 文档在实际获得最佳模型之前就停止了。谁能告诉我最后
在sklearn中,可以定义串行管道以获得管道所有连续部分的超参数的最佳组合。串行管道可以按如下方式实现: from sklearn.svm import SVC from sklearn impor
尝试理解并实现 Keras 回归的 GridSearch 方法。这是我的简单可生成的回归应用程序。 import pandas as pd import numpy as np import skle
我正在尝试在十重交叉验证中的每个人中进行 GridSearch 以获得最佳超参数,它在我之前的多类分类工作中运行良好,但这次在多标签工作中情况并非如此。 X_train, X_test, y_trai
我正在尝试为使用 keras 构建的神经网络执行参数调整。这是我的代码,在导致错误的行上有注释: from sklearn.cross_validation import StratifiedKFol
我正在对多标签数据进行网格搜索,如下所示: #imports from sklearn.svm import SVC as classifier from sklearn.pipeline impor
我是一名优秀的程序员,十分优秀!