【问题标题】:"Unwrapping" SklearnClassifier Object - NLTK Python“展开” SklearnClassifier 对象 - NLTK Python
【发布时间】:2015-08-03 18:20:06
【问题描述】:

我使用 NLTK python 包中的 SklearnClassifier() 包装器来训练几个 sklearn 分类器(LogisticRegression() 和 RandomForest()),以解决文本是特征的二进制分类问题。是否有任何功能允许“解包”该对象,以便可以访问诸如参数估计(用于逻辑回归)或随机森林中的变量重要性列表(或原始 sklearn 对象中可用的任何项目)之类的东西? nltk 分类器对象可以对新实例进行评分,因此基础信息必须包含在该对象中的某处?谢谢你的想法。

【问题讨论】:

  • 欢迎来到 Stack Overflow!您可能想查看how to ask a question。正确格式化您的问题将大大有助于获得您正在寻找的答案。

标签: python scikit-learn nltk


【解决方案1】:

您的分类器隐藏在 _clf 变量下。

classifier = SKLearnClassifier(MLPClassifier())
mlp = classifier._clf

http://www.nltk.org/_modules/nltk/classify/scikitlearn.html 找到的文档:

def __init__(self, estimator, dtype=float, sparse=True):
    """
    :param estimator: scikit-learn classifier object.

    :param dtype: data type used when building feature array.
        scikit-learn estimators work exclusively on numeric data. The
        default value should be fine for almost all situations.

    :param sparse: Whether to use sparse matrices internally.
        The estimator must support these; not all scikit-learn classifiers
        do (see their respective documentation and look for "sparse
        matrix"). The default value is True, since most NLP problems
        involve sparse feature sets. Setting this to False may take a
        great amount of memory.
    :type sparse: boolean.
    """
    self._clf = estimator
    self._encoder = LabelEncoder()
    self._vectorizer = DictVectorizer(dtype=dtype, sparse=sparse)

【讨论】:

  • 已经有一段时间了。我不确定这是一个新功能还是我错过了它。谢谢!
猜你喜欢
  • 2013-12-22
  • 2017-03-12
  • 2017-07-29
  • 2019-08-04
  • 1970-01-01
  • 1970-01-01
  • 2020-12-27
  • 2015-01-27
  • 2016-08-26
相关资源
最近更新 更多