Module Expr Str ImportFrom alias alias ImportFrom alias ImportFrom alias ImportFrom alias TryExcept body ImportFrom alias ImportFrom alias handlers ExceptHandler type NameLoad body Pass Assign NameStore ListLoad Str ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad NameLoad body Expr Str Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr Call NameLoad Assign AttributeStore NameLoad attr Call NameLoad keyword NameLoad keyword NameLoad decorator_list FunctionDef arguments args NameParam defaults body Return BinOpMod Str AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore AttributeLoad AttributeLoad NameLoad attr attr Return ListComp SubscriptLoad NameLoad Index NameLoad comprehension NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Return ListComp Call AttributeLoad NameLoad attr NameLoad comprehension NameStore NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign TupleStore NameStore NameStore Call NameLoad Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Assign NameStore AttributeLoad AttributeLoad NameLoad attr attr Return Call NameLoad Call NameLoad GeneratorExp TupleLoad SubscriptLoad NameLoad Index NameLoad NameLoad comprehension TupleStore NameStore NameStore Call NameLoad NameLoad decorator_list decorator_list AttributeLoad NameLoad attr FunctionDef arguments args NameParam defaults body ImportFrom alias TryExcept body Import alias handlers ExceptHandler type NameLoad body Raise Call NameLoad Str decorator_list If CompareEq NameLoad Str body ImportFrom alias alias ImportFrom alias ImportFrom alias Expr Call NameLoad Str Expr Call NameLoad AttributeLoad Call NameLoad Call NameLoad keyword NameLoad attr keyword NameLoad Expr Call NameLoad Str Expr Call NameLoad AttributeLoad Call NameLoad Call NameLoad keyword Num attr keyword NameLoad
N/A N/A 
scikit-learn (http://scikit-learn.org) is a machine learning library for
Python. It supports many classification algorithms, including SVMs,
Naive Bayes, logistic regression (MaxEnt) and decision trees.

This package implement a wrapper around scikit-learn classifiers. To use this
wrapper, construct a scikit-learn estimator object, then use that to construct
a SklearnClassifier. E.g., to wrap a linear SVM with default settings:

>>> from sklearn.svm import LinearSVC
>>> from nltk.classify.scikitlearn import SklearnClassifier
>>> classif = SklearnClassifier(LinearSVC())

A scikit-learn classifier may include preprocessing steps when it's wrapped
in a Pipeline object. The following constructs and wraps a Naive Bayes text
classifier with tf-idf weighting and chi-square feature selection to get the
best 1000 features:

>>> from sklearn.feature_extraction.text import TfidfTransformer
>>> from sklearn.feature_selection import SelectKBest, chi2
>>> from sklearn.naive_bayes import MultinomialNB
>>> from sklearn.pipeline import Pipeline
>>> pipeline = Pipeline([('tfidf', TfidfTransformer()),
...                      ('chi2', SelectKBest(chi2, k=1000)),
...                      ('nb', MultinomialNB())])
>>> classif = SklearnClassifier(pipeline)
 __future__ print_function unicode_literals nltk.classify.api ClassifierI nltk.probability DictionaryProbDist nltk compat N/A N/A sklearn.feature_extraction DictVectorizer sklearn.preprocessing LabelEncoder N/A N/A N/A ImportError N/A N/A N/A __all__ N/A SklearnClassifier SklearnClassifier N/A ClassifierI N/A N/A Wrapper for scikit-learn classifiers. __init__ N/A N/A self estimator dtype sparse N/A float True N/A N/A 
        :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.
         N/A N/A self _clf estimator N/A N/A self _encoder N/A LabelEncoder N/A N/A self _vectorizer N/A DictVectorizer dtype dtype sparse sparse N/A __repr__ N/A N/A self N/A N/A N/A N/A <SklearnClassifier(%r)> N/A self _clf N/A classify_many N/A N/A self featuresets N/A N/A N/A Classify a batch of samples.

        :param featuresets: An iterable over featuresets, each a dict mapping
            strings to either numbers, booleans or strings.
        :return: The predicted class label for each input sample.
        :rtype: list
         N/A X N/A N/A N/A self _vectorizer transform featuresets N/A classes N/A N/A self _encoder classes_ N/A N/A N/A classes N/A i N/A i N/A N/A N/A self _clf predict X N/A prob_classify_many N/A N/A self featuresets N/A N/A N/A Compute per-class probabilities for a batch of samples.

        :param featuresets: An iterable over featuresets, each a dict mapping
            strings to either numbers, booleans or strings.
        :rtype: list of ``ProbDistI``
         N/A X N/A N/A N/A self _vectorizer transform featuresets N/A y_proba_list N/A N/A N/A self _clf predict_proba X N/A N/A N/A N/A self _make_probdist y_proba N/A y_proba y_proba_list N/A labels N/A N/A self N/A N/A N/A The class labels used by this classifier.

        :rtype: list
         N/A N/A list N/A N/A self _encoder classes_ N/A train N/A N/A self labeled_featuresets N/A N/A N/A 
        Train (fit) the scikit-learn estimator.

        :param labeled_featuresets: A list of ``(featureset, label)``
            where each ``featureset`` is a dict mapping strings to either
            numbers, booleans or strings.
         N/A N/A X y N/A list N/A N/A compat izip labeled_featuresets N/A X N/A N/A N/A self _vectorizer fit_transform X N/A y N/A N/A N/A self _encoder fit_transform y N/A N/A N/A N/A self _clf fit X y N/A self N/A _make_probdist N/A N/A self y_proba N/A N/A N/A classes N/A N/A self _encoder classes_ N/A N/A DictionaryProbDist N/A dict N/A N/A N/A classes N/A i p N/A N/A i p N/A enumerate y_proba N/A N/A N/A compat python_2_unicode_compatible setup_module N/A N/A module N/A N/A nose SkipTest N/A N/A N/A sklearn N/A N/A N/A ImportError N/A N/A N/A SkipTest scikit-learn is not installed N/A N/A N/A __name__ __main__ N/A nltk.classify.util names_demo names_demo_features sklearn.linear_model LogisticRegression sklearn.naive_bayes BernoulliNB N/A N/A print scikit-learn Naive Bayes: N/A N/A names_demo N/A N/A SklearnClassifier N/A BernoulliNB binarize False train features names_demo_features N/A N/A print 

scikit-learn logistic regression: N/A N/A names_demo N/A N/A SklearnClassifier N/A LogisticRegression C 1000 train features names_demo_features