- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 sklearn 库在 LatentDirichletAllocation 上应用 GridSearchCV。
vectorizer = CountVectorizer(analyzer='word',
min_df=10,
stop_words='english',
lowercase=True,
token_pattern='[a-zA-Z0-9]{3,}'
)
data_vectorized = vectorizer.fit_transform(doc_clean) #where doc_clean is processed text.
lda_model = LatentDirichletAllocation(n_components =number_of_topics,
max_iter=10,
learning_method='online',
random_state=100,
batch_size=128,
evaluate_every = -1,
n_jobs = -1,
)
search_params = {'n_components': [10, 15, 20, 25, 30], 'learning_decay': [.5, .7, .9]}
model = GridSearchCV(lda_model, param_grid=search_params)
model.fit(data_vectorized)
目前 GridSearchCV 使用近似对数似然作为分数来确定哪个是最佳模型。我想做的是将我的评分方法更改为基于 approximate perplexity代替模型。
根据 sklearn 的 documentation of GridSearchCV ,有一个我可以使用的评分参数。但是,我不知道如何应用困惑度作为评分方法,而且我在网上找不到任何人应用它的例子。这可能吗?
最佳答案
GridSearchCV
默认情况下将使用管道中最终估计器的 score()
函数。
make_scorer
可以在这里使用,但是为了计算困惑度,您还需要来自拟合模型的其他数据,通过 make_scorer
提供这些数据可能有点复杂。
您可以在此处对 LDA 进行包装,您可以在其中重新实现 score()
函数以返回 perplexity
。沿线的东西:
class MyLDAWithPerplexityScorer(LatentDirichletAllocation):
def score(self, X, y=None):
# You can change the options passed to perplexity here
score = super(MyLDAWithPerplexityScorer, self).perplexity(X, sub_sampling=False)
# Since perplexity is lower for better, so we do negative
return -1*score
然后可以在您的代码中使用它代替 LatentDirichletAllocation
,例如:
...
...
...
lda_model = MyLDAWithPerplexityScorer(n_components =number_of_topics,
....
....
n_jobs = -1,
)
...
...
关于python - sklearn.model_selection.GridSearchCV 对 LatentDirichletAllocation 的评分策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52986253/
>>> import sklearn.model_selection.train_test_split Traceback (most recent call last): File "", li
在 probability calibration of classifiers来自scikit-learn,有一段关于train_test_split的代码我在文档中找不到解释。 centers =
我将 train_test_split 导入为: from sklearn.model_selection import train_test_split 并且给出了一个错误 cannot impor
我知道 sklearn.model_selection.cross_val_score 函数使用了一个 make_scorer() 函数,该函数返回一个对估计器输出进行评分的可调用函数。cross_v
我想在 GridSearchCV 中定义一个新的评分,正如这里所述 http://scikit-learn.org/stable/modules/model_evaluation.html#imple
我正在尝试从数据中进行线性回归,但是当我尝试以下操作时: from sklearn.model_selection import train_test_split from sklearn.linea
因此,我需要使用预定义的组生成测试/训练/验证拆分。我不想使用 LeavePGroupsOut 因为我需要根据我想要的百分比将数据分离到训练和验证集中。在GroupShuffleSplit的文档中,对
我正在尝试使用 train_test_split 函数并编写: from sklearn.model_selection import train_test_split 这会导致 ImportErro
当我想使用sklearn.model_selection.train_test_split来分割训练集和测试集时,它会引发如下错误: AttributeError: module 'sklearn'
我正在制作一个具有不平衡类(比例为 1:10)的二元分类器。我尝试了 KNN、RF 和 XGB 分类器。我从 XGB 分类器中获得了最佳的精确召回权衡和 F1 分数(可能是因为数据集的大小非常小 -
我正在尝试运行 this example从 sklearn 更好地理解他们的 TfidfTransformer 来自 sklearn.feature_extraction.text。但是,我返回了 T
我正在尝试通过 Python 中的 Keras 深度学习库学习神经网络。我正在使用 Python 3 并引用此链接:Tutorial Link 我尝试运行下面的代码,但出现以下错误: 导入错误:没有名
我在做this tutorial关于机器学习,其中使用了以下代码: import pandas as pd from sklearn.model_selection import train_test
当我尝试使用 StratifiedGroupKFold 时出现 ImportError从 sklearn 中拆分出来。 我注意到使用它需要夜间构建并且我已经安装了它,但我收到错误。欢迎就如何解决此问题
我正在尝试使用 sklearn 库在 LatentDirichletAllocation 上应用 GridSearchCV。 当前流水线如下所示: vectorizer = CountVectoriz
我正在尝试使用 sklearn 库在 LatentDirichletAllocation 上应用 GridSearchCV。 当前流水线如下所示: vectorizer = CountVectoriz
我正在尝试使用 sklearn.model_selection 中的 GridSearhCV 进行参数调整 我不知何故不断收到 ValueError: C in () 1 gs = Gr
我最近开始使用 sklearn 并偶然发现了 Stratified ShuffleSplit 函数。尽管我理解它的概念和它的用途,但我不太理解它运行所需的参数,例如n_split。根据sklearn的
我正在使用 svm 对新闻组主题进行分类。我正在提供最好的解决方案来对这些数据进行分类。请帮助删除这个错误,它阻止了我的整个项目。在这里,当我通过 GridSearchCV 库调用拟合方法时,它显示了
我正在尝试使用 GridSearchCV 实现决策树分类器。实现后,我尝试访问 cv_results_.mean_train_score 但出现关键错误。 tuned_parameters =
我是一名优秀的程序员,十分优秀!