{"id":264868,"date":"2015-09-03T21:30:11","date_gmt":"2015-09-03T17:30:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=264868"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=264868","title":{"rendered":"\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 scikit-learn (\u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438) \u2014 \u0447\u0430\u0441\u0442\u044c 2"},"content":{"rendered":"<p>     \t<i>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0433\u043b\u0430\u0432\u044b, \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 <a href=\"http:\/\/scikit-learn.org\/0.15\/tutorial\/text_analytics\/working_with_text_data.html\">scikit-learn.<\/a> \u041d\u0430\u0447\u0430\u043b\u043e \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u0432 <a href=\"http:\/\/habrahabr.ru\/post\/264339\/\">\u0447\u0430\u0441\u0442\u0438 1<\/a>.<\/i><\/p>\n<h3>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u044b\u0434\u0435\u043b\u0438\u043b\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e \u0442\u0435\u043a\u0441\u0442\u0430. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 <a href=\"http:\/\/scikit-learn.org\/stable\/modules\/naive_bayes.html#naive-bayes\">\u041d\u0430\u0438\u0432\u043d\u043e\u0433\u043e \u0411\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. scikit-learn \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430. \u0421\u0430\u043c\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0441\u043b\u043e\u0432 \u2014 \u044d\u0442\u043e \u0435\u0433\u043e \u043f\u043e\u043b\u0438 \u043d\u043e\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from sklearn.naive_bayes import MultinomialNB &gt;&gt;&gt; clf = MultinomialNB().fit(X_train_tfidf, twenty_train.target)<\/code><\/pre>\n<p>  <a name=\"habracut\"><\/a><br \/>  \u0427\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u0430 \u043d\u043e\u0432\u043e\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435, \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0444\u0438\u0447\u0438 (\u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u0447\u0442\u0438 \u0442\u0430\u043a\u0443\u044e \u0436\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u0435\u0435. \u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 transform \u0432\u043c\u0435\u0441\u0442\u043e fit_transform \u0438\u0437 transformers, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0438 \u0443\u0436\u0435 \u0431\u044b\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u043a \u043d\u0430\u0448\u0435\u0439 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; docs_new = ['God is love', 'OpenGL on the GPU is fast'] &gt;&gt;&gt; X_new_counts = count_vect.transform(docs_new) &gt;&gt;&gt; X_new_tfidf = tfidf_transformer.transform(X_new_counts)  &gt;&gt;&gt; predicted = clf.predict(X_new_tfidf)  &gt;&gt;&gt; for doc, category in zip(docs_new, predicted): ...     print('%r =&gt; %s' % (doc, twenty_train.target_names[category])) ... 'God is love' =&gt; soc.religion.christian 'OpenGL on the GPU is fast' =&gt; comp.graphics<\/code><\/pre>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/h3>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0441 \u0446\u0435\u043f\u043e\u0447\u043a\u043e\u0439 vectorizer =&gt; transformer =&gt; classifier \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0449\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0432 scikit-learn \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 Pipeline, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u0443\u0435\u0442 \u043a\u0430\u043a \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 (\u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u043d\u044b\u0439) \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from sklearn.pipeline import Pipeline &gt;&gt;&gt; text_clf = Pipeline([('vect', CountVectorizer()), ...                      ('tfidf', TfidfTransformer()), ...                      ('clf', MultinomialNB()), ... ])<\/code><\/pre>\n<p>  \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 vect, tfidf and clf (\u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440) \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u043d\u0430\u043c\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0438\u0436\u0435, \u0432 \u0433\u043b\u0430\u0432\u0435 grid search. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0443\u0447\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0435\u0433\u043e 1 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; text_clf = text_clf.fit(twenty_train.data, twenty_train.target)<\/code><\/pre>\n<h3>\u041e\u0446\u0435\u043d\u043a\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435<\/h3>\n<p>  \u041e\u0446\u0435\u043d\u043a\u0430 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; twenty_test = fetch_20newsgroups(subset='test', ...     categories=categories, shuffle=True, random_state=42) &gt;&gt;&gt; docs_test = twenty_test.data &gt;&gt;&gt; predicted = text_clf.predict(docs_test) &gt;&gt;&gt; np.mean(predicted == twenty_test.target)             0.834...<\/code><\/pre>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 83% \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043e\u043f\u043e\u0440\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 <a href=\"http:\/\/scikit-learn.org\/stable\/modules\/svm.html#svm\">(support vector machine (SVM))<\/a>. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0438\u043c \u0438\u0437 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 (\u0445\u043e\u0442\u044f, \u043e\u043d \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435 \u0447\u0435\u043c \u043d\u0430\u0438\u0432\u043d\u044b\u0439 \u0411\u0430\u0439\u0435\u0441). \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 \u043d\u0430\u0448 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from sklearn.linear_model import SGDClassifier &gt;&gt;&gt; text_clf = Pipeline([('vect', CountVectorizer()), ...                      ('tfidf', TfidfTransformer()), ...                      ('clf', SGDClassifier(loss='hinge', penalty='l2', ...                                            alpha=1e-3, n_iter=5, random_state=42)), ... ]) &gt;&gt;&gt; _ = text_clf.fit(twenty_train.data, twenty_train.target) &gt;&gt;&gt; predicted = text_clf.predict(docs_test) &gt;&gt;&gt; np.mean(predicted == twenty_test.target)             0.912...<\/code><\/pre>\n<p>  scikit-learn \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from sklearn import metrics &gt;&gt;&gt; print(metrics.classification_report(twenty_test.target, predicted, ...     target_names=twenty_test.target_names)) ...                                                                  precision    recall  f1-score   support             alt.atheism       0.95      0.81      0.87       319          comp.graphics       0.88      0.97      0.92       389                sci.med       0.94      0.90      0.92       396 soc.religion.christian       0.90      0.95      0.93       398             avg \/ total       0.92      0.91      0.91      1502   &gt;&gt;&gt; metrics.confusion_matrix(twenty_test.target, predicted) array([[258,  11,  15,  35],        [  4, 379,   3,   3],        [  5,  33, 355,   3],        [  5,  10,   4, 379]])<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0442\u0435\u043a\u0441\u0442\u044b \u0438\u0437 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 newsgroups \u043e\u0431 \u0430\u0442\u0435\u0438\u0437\u043c\u0435 \u0438 \u0445\u0440\u0438\u0441\u0442\u0438\u0430\u043d\u0441\u0442\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0447\u0430\u0449\u0435 \u043f\u0443\u0442\u0430\u0435\u0442 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c, \u043d\u0435\u0436\u0435\u043b\u0438 \u0447\u0435\u043c \u0441 \u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 \u043f\u0440\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u0443\u044e \u0433\u0440\u0430\u0444\u0438\u043a\u0443.<\/p>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f grid search<\/h3>\n<p>  \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u044b \u0443\u0436\u0435 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a use_idf \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 TfidfTransformer. \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u044e\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, MultinomialNB \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0441\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u044f alpha, \u0430 SGDClassifier \u0438\u043c\u0435\u0435\u0442 \u0448\u0442\u0440\u0430\u0444\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 alpha (\u043c\u0435\u0442\u043e\u0434 \u0448\u0442\u0440\u0430\u0444\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439), \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u0443\u044e \u043f\u043e\u0442\u0435\u0440\u044e \u0438 \u0448\u0442\u0440\u0430\u0444\u043d\u044b\u0435 \u0447\u043b\u0435\u043d\u044b \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0441\u043c. \u0440\u0430\u0437\u0434\u0435\u043b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 Python, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e).<br \/>  \u0412\u043c\u0435\u0441\u0442\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0432 \u0446\u0435\u043f\u0438, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0438\u0441\u043a (\u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 ) \u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u0441\u0435\u0442\u043a\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u041c\u044b \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b\u0438 \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u043d\u0430 \u0441\u043b\u043e\u0432\u0430\u0445 \u0438\u043b\u0438 \u0431\u0438\u0433\u0440\u0430\u043c\u043c\u0430\u0445, \u0441 \u0438\u043b\u0438 \u0431\u0435\u0437 idf, \u0441 \u0448\u0442\u0440\u0430\u0444\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 0,01 \u0438 0,001 \u0434\u043b\u044f SVM (\u043c\u0435\u0442\u043e\u0434\u0430 \u043e\u043f\u043e\u0440\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432):<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from sklearn.grid_search import GridSearchCV &gt;&gt;&gt; parameters = {'vect__ngram_range': [(1, 1), (1, 2)], ...               'tfidf__use_idf': (True, False), ...               'clf__alpha': (1e-2, 1e-3), ... }<\/code><\/pre>\n<p>  \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u043c. \u0415\u0441\u043b\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u0440\u0430\u0441\u043f\u043e\u0440\u044f\u0436\u0435\u043d\u0438\u0438 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u044f\u0434\u0435\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c grid search, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c n_jobs. \u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u044d\u0442\u043e\u043c\u0443 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 -1, grid search \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442, \u043a\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u044f\u0434\u0435\u0440 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e, \u0438 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u0445 \u0432\u0441\u0435:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; gs_clf = GridSearchCV(text_clf, parameters, n_jobs=-1)<\/code><\/pre>\n<p>  \u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 grid search \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c scikit-learn. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u043e\u0438\u0441\u043a \u043d\u0430 \u043c\u0430\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; gs_clf = gs_clf.fit(twenty_train.data[:400], twenty_train.target[:400])<\/code><\/pre>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 fit \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 GridSearchCV \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 predict:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; twenty_train.target_names[gs_clf.predict(['God is love'])] 'soc.religion.christian'<\/code><\/pre>\n<p>  \u043d\u043e \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0438\u0437\u0443\u0447\u0430\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 grid_scores_, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u043f\u0430\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b\\\u043c\u0435\u0440\u0430. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043c\u0435\u0440, \u043c\u044b \u043c\u043e\u0436\u0435\u043c:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; best_parameters, score, _ = max(gs_clf.grid_scores_, key=lambda x: x[1]) &gt;&gt;&gt; for param_name in sorted(parameters.keys()): ...     print(&quot;%s: %r&quot; % (param_name, best_parameters[param_name])) ... clf__alpha: 0.001 tfidf__use_idf: True vect__ngram_range: (1, 1)  &gt;&gt;&gt; score                                               0.900...<\/code><\/pre>\n<p>  <\/p>\n<h3>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f<\/h3>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f, \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0439\u0442\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043f\u0430\u043f\u043a\u0438 \u2018skeletons\u2019 \u0432 \u043d\u043e\u0432\u0443\u044e \u043f\u0430\u043f\u043a\u0443 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u2018workspace\u2019:<\/p>\n<pre><code class=\"python\">% cp -r skeletons workspace<\/code><\/pre>\n<p>  \u0412\u042b \u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043f\u0430\u043f\u043a\u0438 workspace, \u043d\u0435 \u0431\u043e\u044f\u0441\u044c \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0439.<br \/>  \u0417\u0430\u0442\u0435\u043c \u043e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0443 ipython \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043d\u0435\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">[1] %run workspace\/exercise_XX_script.py arg1 arg2 arg3<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 %debug, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u0443\u044e ipdb \u0441\u0435\u0441\u0441\u0438\u044e.<br \/>  \u041e\u0447\u0438\u0441\u0442\u0438\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0439\u0442\u0435, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0435\u0448\u0438\u0442\u0435 \u0437\u0430\u0434\u0430\u0447\u0443.<br \/>  <b>\u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0438 \u0444\u0430\u0439\u043b\u044b skeleton \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0430, \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043b\u044f \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<\/b><\/p>\n<h3>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f 1: \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u044f\u0437\u044b\u043a\u0430<\/h3>\n<p>  <\/p>\n<ul>\n<li>\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440 \u2014 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438 CharNGramAnalyzer. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0438\u0437 Wikipedia. <\/li>\n<li>\u041e\u0446\u0435\u043d\u0438\u0442\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u043b\u044e\u0431\u043e\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435, \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0439 \u0441 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439.<\/li>\n<\/ul>\n<p>  ipython \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430:  <\/p>\n<pre><code class=\"python\">%run workspace\/exercise_01_language_train_model.py data\/languages\/paragraphs\/<\/code><\/pre>\n<h3>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 2: \u0410\u043d\u0430\u043b\u0438\u0437 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043e\u0442\u0437\u044b\u0432\u043e\u0432 \u0444\u0438\u043b\u044c\u043c\u043e\u0432<\/h3>\n<p>  <\/p>\n<ul>\n<li>\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440 \u2014 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043e\u0442\u0437\u044b\u0432\u043e\u0432 \u043e \u0444\u0438\u043b\u044c\u043c\u0430\u0445 \u043d\u0430 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435.<\/li>\n<li>\u041f\u043e\u0434\u0431\u0435\u0440\u0438\u0442\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f grid search. <\/li>\n<li>\u041e\u0446\u0435\u043d\u0438\u0442\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435.<\/li>\n<\/ul>\n<p>  ipython \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430:  <\/p>\n<pre><code class=\"python\">%run workspace\/exercise_02_sentiment.py data\/movie_reviews\/txt_sentoken\/<\/code><\/pre>\n<h3>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f 3: \u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u2014 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 (\u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435)<\/h3>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0439 \u0438 \u043c\u043e\u0434\u0443\u043b\u044c cPickle \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u044f\u0437\u044b\u043a \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 stdin (\u0432\u0432\u043e\u0434 \u0441 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b) \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c (\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0438\u043b\u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439), \u0435\u0441\u043b\u0438 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c.<\/p>\n<h3>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/h3>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0435\u043a\u0446\u0438\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0432\u0435\u0442\u044b, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c \u0433\u043b\u0443\u0431\u0436\u0435 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 scikit-learn \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0439:  <\/p>\n<ul>\n<li>\u041f\u043e\u043f\u044b\u0442\u0430\u0439\u0442\u0435\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c analyzer \u0438 token normalisation \u0432 <a href=\"http:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.feature_extraction.text.CountVectorizer.html#sklearn.feature_extraction.text.CountVectorizer\">CountVectorizer<\/a> <\/li>\n<li>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"http:\/\/scikit-learn.org\/stable\/auto_examples\/text\/document_clustering.html#example-text-document-clustering-py\">\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e<\/a> \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. <\/li>\n<li>\u0415\u0441\u043b\u0438 \u0432\u0430\u0448 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u0442\u0435\u0433\u0430\u043c\u0438, \u0442.\u0435. \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\u043c\u0438, \u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u0441\u0435\u043a\u0446\u0438\u044e <a href=\"http:\/\/scikit-learn.org\/stable\/modules\/multiclass.html#multiclass\">Multiclass and multilabel<\/a> <\/li>\n<li>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"http:\/\/scikit-learn.org\/stable\/modules\/decomposition.html#lsa\">Truncated SVD<\/a> \u0434\u043b\u044f <a href=\"http:\/\/en.wikipedia.org\/wiki\/Latent_semantic_analysis\">\u043b\u0430\u0442\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430<\/a>. <\/li>\n<li>\u041f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u044c\u0442\u0435\u0441\u044c \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"http:\/\/scikit-learn.org\/stable\/auto_examples\/applications\/plot_out_of_core_classification.html#example-applications-plot-out-of-core-classification-py\">Out-of-core Classification<\/a> \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/li>\n<li>\u041f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u044c\u0442\u0435\u0441\u044c \u0441 <a href=\"http:\/\/scikit-learn.org\/stable\/modules\/feature_extraction.html#hashing-vectorizer\">Hashing Vectorizer<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 <a href=\"http:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.feature_extraction.text.CountVectorizer.html#sklearn.feature_extraction.text.CountVectorizer\">CountVectorizer<\/a>. <\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/266025\/\"> http:\/\/habrahabr.ru\/post\/266025\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t<i>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0433\u043b\u0430\u0432\u044b, \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 <a href=\"http:\/\/scikit-learn.org\/0.15\/tutorial\/text_analytics\/working_with_text_data.html\">scikit-learn.<\/a> \u041d\u0430\u0447\u0430\u043b\u043e \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0447\u0435\u0441\u0442\u044c \u0432 <a href=\"http:\/\/habrahabr.ru\/post\/264339\/\">\u0447\u0430\u0441\u0442\u0438 1<\/a>.<\/i><\/p>\n<h3>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u044b\u0434\u0435\u043b\u0438\u043b\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0443\u0447\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044e \u0442\u0435\u043a\u0441\u0442\u0430. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 <a href=\"http:\/\/scikit-learn.org\/stable\/modules\/naive_bayes.html#naive-bayes\">\u041d\u0430\u0438\u0432\u043d\u043e\u0433\u043e \u0411\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. scikit-learn \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430. \u0421\u0430\u043c\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0441\u043b\u043e\u0432 \u2014 \u044d\u0442\u043e \u0435\u0433\u043e \u043f\u043e\u043b\u0438 \u043d\u043e\u043c\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from sklearn.naive_bayes import MultinomialNB &gt;&gt;&gt; clf = MultinomialNB().fit(X_train_tfidf, twenty_train.target)<\/code><\/pre>\n<p>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-264868","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/264868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=264868"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/264868\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=264868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=264868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=264868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}