JL iDdZddlmZddlmZ ddlmZddlmZdgZ GddeZ e dk(rgdd l mZdd lmZdd lmZmZed ee ed j*eedee edj*eyy#e $rYwxYw)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) LabelEncoderSklearnClassifierc@eZdZdZedfdZdZdZdZdZ dZ d Z y ) rz%Wrapper for scikit-learn classifiers.TcT||_t|_t|||_y)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. )dtypesparseN)_clfr_encoderr _vectorizer)self estimatorr r s _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/classify/scikitlearn.py__init__zSklearnClassifier.__init__1s#  $ )fEc d|jzS)Nz)r rs r__repr__zSklearnClassifier.__repr__Es(49944rc|jj|}|jj}|jj |Dcgc]}|| c}Scc}w)aClassify 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 featuresetsXclassesis r classify_manyzSklearnClassifier.classify_manyHsP    & &{ 3--(($(II$5$5a$89q 999s Ac|jj|}|jj|}|Dcgc]}|j |c}Scc}w)zCompute 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`` )rrr predict_proba_make_probdist)rrr y_proba_listy_probas rprob_classify_manyz$SklearnClassifier.prob_classify_manyTsM    & &{ 3yy..q1 rKs 8*/ 92  JR JRZ z7/B %&+u56<<$ 12,t45;;$#g  s BBB