ó
    /ë”h  ã                   ó0  • S r SSKJr  SSKJr   SSKJr  SSKJr  S/r
 " S S\5      r\S:X  a[  SS	KJr  SS
KJr  SSKJrJr  \" S5        \" \" \" SS95      R*                  \S9  \" S5        \" \" \" SS95      R*                  \S9  gg! \	 a     Nxf = f)aê  
scikit-learn (https://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 implements 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)
é    )ÚClassifierI)ÚDictionaryProbDist)ÚDictVectorizer)ÚLabelEncoderÚSklearnClassifierc                   óJ   • \ rS rSrSr\S4S jrS rS rS r	S r
S	 rS
 rSrg)r   é.   z%Wrapper for scikit-learn classifiers.Tc                 óJ   • Xl         [        5       U l        [        X#S9U l        g)ad  
: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.
)ÚdtypeÚsparseN)Ú_clfr   Ú_encoderr   Ú_vectorizer)ÚselfÚ	estimatorr   r   s       ÚQ/var/www/auris/envauris/lib/python3.13/site-packages/nltk/classify/scikitlearn.pyÚ__init__ÚSklearnClassifier.__init__1   s   € ð  Œ	Ü$›ˆŒÜ)°ÑEˆÕó    c                 ó    • SU R                   -  $ )Nz<SklearnClassifier(%r)>)r   ©r   s    r   Ú__repr__ÚSklearnClassifier.__repr__E   s   € Ø(¨4¯9©9Ñ4Ð4r   c                 óÊ   • U R                   R                  U5      nU R                  R                  nU R                  R                  U5       Vs/ s H  oCU   PM	     sn$ s  snf )zß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
)r   Ú	transformr   Úclasses_r   Úpredict)r   ÚfeaturesetsÚXÚclassesÚis        r   Úclassify_manyÚSklearnClassifier.classify_manyH   sT   € ð ×Ñ×&Ñ& {Ó3ˆØ—-‘-×(Ñ(ˆØ$(§I¡I×$5Ñ$5°aÔ$8Ó9Ò$8˜q˜”
Ñ$8Ñ9Ð9ùÒ9s   ÁA c                 óº   • U R                   R                  U5      nU R                  R                  U5      nU Vs/ s H  o@R	                  U5      PM     sn$ s  snf )zÑ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``
)r   r   r   Úpredict_probaÚ_make_probdist)r   r   r   Úy_proba_listÚy_probas        r   Úprob_classify_manyÚ$SklearnClassifier.prob_classify_manyT   sO   € ð ×Ñ×&Ñ& {Ó3ˆØ—y‘y×.Ñ.¨qÓ1ˆÙ<HÓIºL°×#Ñ# GÖ,¹LÑIÐIùÒIs   »Ac                 ó@   • [        U R                  R                  5      $ )z8The class labels used by this classifier.

:rtype: list
)Úlistr   r   r   s    r   ÚlabelsÚSklearnClassifier.labels_   s   € ô
 D—M‘M×*Ñ*Ó+Ð+r   c                 óÎ   • [        [        U6 5      u  p#U R                  R                  U5      nU R                  R                  U5      nU R
                  R                  X#5        U $ )zÌ
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.
)r,   Úzipr   Úfit_transformr   r   Úfit)r   Úlabeled_featuresetsr   Úys       r   ÚtrainÚSklearnClassifier.trainf   sU   € ô ”CÐ,Ð-Ó.‰ˆØ×Ñ×*Ñ*¨1Ó-ˆØM‰M×'Ñ'¨Ó*ˆØ	‰	‰aÔàˆr   c                 ó’   • U R                   R                  n[        [        U5       VVs0 s H
  u  p4X#   U_M     snn5      $ s  snnf )N)r   r   r   Ú	enumerate)r   r(   r    r!   Úps        r   r&   Ú SklearnClassifier._make_probdistv   s=   € Ø—-‘-×(Ñ(ˆÜ!¼YÀwÔ=OÔ"PÒ=O±T°Q 7¡:¨q¢=Ñ=OÒ"PÓQÐQùÓ"Ps   ªA
)r   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úfloatr   r   r"   r)   r-   r5   r&   Ú__static_attributes__© r   r   r   r   .   s0   † Ù/à(-°dô Fò(5ò
:ò	Jò,òõ Rr   Ú__main__)ÚLogisticRegression)ÚBernoulliNB)Ú
names_demoÚnames_demo_featureszscikit-learn Naive Bayes:F)Úbinarize)Úfeaturesz#

scikit-learn logistic regression:iè  )ÚCN)r?   Únltk.classify.apir   Únltk.probabilityr   Úsklearn.feature_extractionr   Úsklearn.preprocessingr   ÚImportErrorÚ__all__r   r;   Úsklearn.linear_modelrD   Úsklearn.naive_bayesrE   Únltk.classify.utilrF   rG   Úprintr5   rB   r   r   Ú<module>rU      s¸   ðñõ8 *Ý /ð	Ý9Ý2ð Ð
€ôJR˜ô JRðZ ˆzÓÝ7Ý/çBñ 
Ð
%Ô&ÙÙ™+¨uÑ5Ó6×<Ñ<Ø$òñ 
Ð
1Ô2ÙÙÑ,¨tÑ4Ó5×;Ñ;Ø$óð# øðg ó 	Ùð	ús   B ÂBÂB