Best Python code snippet using slash
feature_extractor.py
Source:feature_extractor.py  
1# coding=utf-82from itertools import chain3from pickle import dump4from nltk import bigrams5from nltk.classify.scikitlearn import SklearnClassifier6from nltk.collocations import BigramCollocationFinder7from nltk.metrics import BigramAssocMeasures8from nltk.probability import FreqDist, ConditionalFreqDist9from sklearn.linear_model import LogisticRegression10from sklearn.metrics import accuracy_score11from sklearn.naive_bayes import MultinomialNB, BernoulliNB12from sklearn.svm import SVC, LinearSVC, NuSVC13# Feature extraction function14def bag_of_words(words):15    """16    Use all words as features17    """18    return dict([(word, True) for word in words])19def bigram(words, score_function=BigramAssocMeasures.chi_sq, top_n=200):20    """21    Use bigrams as features (use chi square chose top 200 bigrams)22    """23    bigram_finder = BigramCollocationFinder.from_words(words)24    bigrams = bigram_finder.nbest(score_function, top_n)25    return bag_of_words(bigrams)26def bigram_words(words, score_function=BigramAssocMeasures.chi_sq, n=200):27    """28    Use words and bigrams as features (use chi square chose top 200 bigrams)29    """30    bigram_finder = BigramCollocationFinder.from_words(words)31    bigrams = bigram_finder.nbest(score_function, n)32    return bag_of_words(words + bigrams)33# è®¡ç®æ¯ä¸ªè¯çä¿¡æ¯çµï¼æåä¿¡æ¯éæå¤§çè¯ä½ä¸ºç¹å¾è¯34def calculate_word_scores(positive_data, negative_data):35    positive_words, negative_words = chain_words(positive_data, negative_data)36    return calculate_score(positive_words, negative_words)37def calculate_bigram_scores(positive_data, negative_data):38    positive_words, negative_words = chain_words(positive_data, negative_data)39    positive_bigram_finder = BigramCollocationFinder.from_words(positive_words)40    negative_bigram_finder = BigramCollocationFinder.from_words(negative_words)41    positive_bigrams = positive_bigram_finder.nbest(BigramAssocMeasures.chi_sq, 8000)42    negative_bigrams = negative_bigram_finder.nbest(BigramAssocMeasures.chi_sq, 8000)43    return calculate_score(negative_bigrams, positive_bigrams)44def calculate_word_bigram_scores(positive_data, negative_data):45    """46    Combine words and bigrams information scores47    """48    positive_words, negative_words = chain_words(positive_data, negative_data)49    positive_bigram_finder = BigramCollocationFinder.from_words(positive_words)50    negative_bigram_finder = BigramCollocationFinder.from_words(negative_words)51    positive_bigrams = positive_bigram_finder.nbest(BigramAssocMeasures.chi_sq, 5000)52    negative_bigrams = negative_bigram_finder.nbest(BigramAssocMeasures.chi_sq, 5000)53    return calculate_score(negative_words + negative_bigrams, positive_words + positive_bigrams)54def chain_words(positive_data, negative_data):55    positive_words = list(chain(*positive_data))56    negative_words = list(chain(*negative_data))57    return positive_words, negative_words58def calculate_score(positive_words, negative_words):59    # é¢çåå¸60    conditional_word_frequency_distribution, word_frequency_distribution = calculate_frequency(positive_words,61                                                                                               negative_words)62    positive_word_count = conditional_word_frequency_distribution['pos'].N()63    negative_word_count = conditional_word_frequency_distribution['neg'].N()64    total_word_count = positive_word_count + negative_word_count65    word_scores = {}66    for word, freq in word_frequency_distribution.iteritems():67        positive_score = BigramAssocMeasures.chi_sq(conditional_word_frequency_distribution['pos'][word],68                                                    (freq, positive_word_count), total_word_count)69        negative_score = BigramAssocMeasures.chi_sq(conditional_word_frequency_distribution['neg'][word],70                                                    (freq, negative_word_count), total_word_count)71        word_scores[word] = positive_score + negative_score72    return word_scores73def calculate_frequency(positive_words, negative_words):74    word_frequency_distribution = FreqDist()75    conditional_word_frequency_distribution = ConditionalFreqDist()76    for word in positive_words:77        word_frequency_distribution[word] += 178        conditional_word_frequency_distribution['pos'][word] += 179    for word in negative_words:80        word_frequency_distribution[word] += 181        conditional_word_frequency_distribution['neg'][word] += 182    return conditional_word_frequency_distribution, word_frequency_distribution83# 5 Second we should extact the most informative words or bigrams based on the information score84def find_best_words(word_scores, number):85    best_vals = sorted(word_scores.iteritems(), key=lambda (w, s): s, reverse=True)[:number]86    best_words = set([w for w, s in best_vals])87    return best_words88# 6 Third we could use the most informative words and bigrams as machine learning features89# Use chi_sq to find most informative words of the review90def best_word_features(words, best_words):91    return dict([(word, True) for word in words if word in best_words])92# Use chi_sq to find most informative bigrams of the review93def best_bigram_features(words, best_words):94    return dict([(word, True) for word in bigrams(words) if word in best_words])95# Use chi_sq to find most informative words and bigrams of the review96def best_combined_features(words, best_words):97    best_word_feature = best_word_features(words, best_words)98    best_bigram_feature = best_bigram_features(words, best_words)99    combined_feature = dict(best_word_feature, **best_bigram_feature)100    return combined_feature101# 7 Transform review to features by setting labels to words in review102def set_positive_label(positive_reviews, feature_extraction_method, best_words):103    posFeatures = []104    for i in positive_reviews:105        posWords = [feature_extraction_method(i, best_words), 'pos']106        posFeatures.append(posWords)107    return posFeatures108def set_negative_label(negative_reviews, feature_extraction_method, best_words):109    negFeatures = []110    for i in negative_reviews:111        negWords = [feature_extraction_method(i, best_words), 'neg']112        negFeatures.append(negWords)113    return negFeatures114def clf_score(classifier, train_set, test, tag_test):115    classifier = SklearnClassifier(classifier)116    classifier.train(train_set)117    predict = classifier.classify_many(test)118    return accuracy_score(tag_test, predict)119def cal_classifier_accuracy(train_set, test, tag_test):120    classifierlist = []121    print 'å个åç±»å¨å度ï¼'122    print 'BernoulliNB`s accuracy is %f' % clf_score(BernoulliNB(), train_set, test, tag_test)123    print 'MultinomiaNB`s accuracy is %f' % clf_score(MultinomialNB(), train_set, test, tag_test)124    print 'LogisticRegression`s accuracy is %f' % clf_score(LogisticRegression(), train_set, test, tag_test)125    print 'SVC`s accuracy is %f' % clf_score(SVC(gamma=0.001, C=100., kernel='linear'), train_set, test, tag_test)126    print 'LinearSVC`s accuracy is %f' % clf_score(LinearSVC(), train_set, test, tag_test)127    print 'NuSVC`s accuracy is %f' % clf_score(NuSVC(), train_set, test, tag_test)128    # print 'GaussianNB`s accuracy is %f' %clf_score(GaussianNB())129    classifierlist.append([BernoulliNB(), clf_score(BernoulliNB(), train_set, test, tag_test)])130    classifierlist.append([MultinomialNB(), clf_score(MultinomialNB(), train_set, test, tag_test)])131    classifierlist.append([LogisticRegression(), clf_score(LogisticRegression(), train_set, test, tag_test)])132    classifierlist.append([SVC(gamma=0.001, C=100., kernel='linear'),133                           clf_score(SVC(gamma=0.001, C=100., kernel='linear'), train_set, test, tag_test)])134    classifierlist.append([LinearSVC(), clf_score(LinearSVC(), train_set, test, tag_test)])135    classifierlist.append([NuSVC(), clf_score(NuSVC(), train_set, test, tag_test)])136    return classifierlist137def find_best_classifier(classifiers):138    max_val = 0139    for c in classifiers:140        if c[1] > max_val:141            max_val = c[1]142            best = c[0]143    return best144def store_classifier(object, train_set, path):145    object_classifier = SklearnClassifier(object)146    object_classifier.train(train_set)147    dump(object_classifier, open(path + '/classifier.pkl', 'w'))148# 4. å è½½åç±»å¨149# clf = pickle.load(open(path+'/classifier.pkl'))150# è®¡ç®æµè¯éçæ¦ç151# pred = clf.prob_classify_many(extract_features(test_review))152# ä¿å153def store_predict_result(path, pred):154    p_file = open(path + '/result/result.txt', 'w')155    for i in pred:156        p_file.write(str(i.prob('pos')) + ' ' + str(i.prob('neg')) + '\n')157    p_file.close()158    pred2 = []159    pos_count = 0160    neg_count = 0161    for i in pred:162        pred2.append([i.prob('pos'), i.prob('neg')])163        if i.prob('pos') > i.prob('neg'):164            pos_count += 1165        else:166            neg_count += 1167    print '好è¯å ï¼', '%f' % ((pos_count * 1.0) / ((pos_count + neg_count) * 1.0))168    print 'å·®è¯å ï¼', '%f' % ((neg_count * 1.0) / ((pos_count + neg_count) * 1.0))169def extract_features(dataset, best_words):170    feat = []171    for i in dataset:172        #         feat.append(best_word_features(i,best_words))173        feat.append(best_combined_features(i, best_words))...tests.py
Source:tests.py  
2from django.test import TestCase3from django.template import Context, Template4from django.template import TemplateSyntaxError5class LatexifyTests(TestCase):6    def tag_test(self, template, context, output):7        t = Template("{}{}".format('{% load latexify %}', template))8        c = Context(context)9        self.assertEqual(t.render(c), output)10    def test__normal_text(self):11        template = '{% latexify test_text %}'12        context = {'test_text': 'hello world'}13        output = '<span class="django-latexify text">hello world</span>'14        self.tag_test(template, context, output)15    def test__parse_math_is_true_and_no_math_in_text(self):16        template = '{% latexify test_text parse_math=True %}'17        context = {'test_text': 'hello world'}18        output = '<span class="django-latexify text">hello world</span>'19        self.tag_test(template, context, output)20    def test__parse_math_is_true_and_inline_math_in_text(self):21        template = '{% latexify test_text parse_math=True %}'22        context = {'test_text': '\$f(x)=\sqrt(2)\$'}23        output = '<span class="django-latexify text">' \24                 '<span class="django-latexify math inline">' \25                 'f(x)=\\sqrt(2)</span>' \26                 '</span>'27        self.tag_test(template, context, output)28    def test__parse_math_is_true_and_block_math_in_text(self):29        template = '{% latexify test_text parse_math=True %}'30        context = {'test_text': '\$$f(x)=\sqrt(2)\$$'}31        output = '<span class="django-latexify text">' \32                 '<span class="django-latexify math block">' \33                 'f(x)=\\sqrt(2)</span>' \34                 '</span>'35        self.tag_test(template, context, output)36    def test__parse_math_is_true_and_block_and_inline_math_in_text(self):37        template = '{% latexify test_text parse_math=True %}'38        context = {'test_text': '\$$f(x)=\sqrt(4)\$$ is \$f(x)=2\$'}39        output = '<span class="django-latexify text">' \40                 '<span class="django-latexify math block">' \41                 'f(x)=\\sqrt(4)</span> is ' \42                 '<span class="django-latexify math inline">f(x)=2</span>' \43                 '</span>'44        self.tag_test(template, context, output)45    def test__parse_math_is_true_and_inline_and_block_math_in_text(self):46        template = '{% latexify test_text parse_math=True %}'47        context = {'test_text': '\$f(x)=\sqrt(4)\$ is \$$f(x)=2\$$'}48        output = '<span class="django-latexify text">' \49                 '<span class="django-latexify math inline">' \50                 'f(x)=\\sqrt(4)</span> is ' \51                 '<span class="django-latexify math block">f(x)=2</span>' \52                 '</span>'53        self.tag_test(template, context, output)54    def test__parse_math_is_true_not_closed_inline_math_tag_in_text(self):55        template = '{% latexify test_text parse_math=True %}'56        context = {'test_text': '\$f(x)=\sqrt(4)'}57        output = '<span class="django-latexify text">\\$f(x)=\\sqrt(4)</span>'58        self.tag_test(template, context, output)59    def test__parse_math_is_true_not_closed_block_math_tag_in_text(self):60        template = '{% latexify test_text parse_math=True %}'61        context = {'test_text': '\$$f(x)=\sqrt(4)'}62        output = '<span class="django-latexify text">' \63                 '\\$$f(x)=\\sqrt(4)' \64                 '</span>'65        self.tag_test(template, context, output)66    def test__parse_math_is_true_unmatching_math_tags_in_text(self):67        template = '{% latexify test_text parse_math=True %}'68        context = {'test_text': '\$$f(x)=\sqrt(4)\$'}69        output = '<span class="django-latexify text">' \70                 '\\$$f(x)=\\sqrt(4)\\$' \71                 '</span>'72        self.tag_test(template, context, output)73    def test__parse_math_is_true_unmatching_math_tags_reversed(self):74        template = '{% latexify test_text parse_math=True %}'75        context = {'test_text': '\$f(x)=\sqrt(4)\$$'}76        output = '<span class="django-latexify text">' \77                 '\\$f(x)=\\sqrt(4)\\$$' \78                 '</span>'79        self.tag_test(template, context, output)80    def test__parse_math_is_true_inline_tag_inside_block_tag(self):81        template = '{% latexify test_text parse_math=True %}'82        context = {'test_text': '\$$g(x)=\$\sqrt(9)\$\$$'}83        output = '<span class="django-latexify text">' \84                 '\\$$g(x)=\\$\\sqrt(9)\\$\\$$' \85                 '</span>'86        self.tag_test(template, context, output)87    def test__parse_math_is_true_block_tag_inside_inline_tag(self):88        template = '{% latexify test_text parse_math=True %}'89        context = {'test_text': '\$y(x)=\$$\sqrt(16)\$$\$'}90        out = '<span class="django-latexify text">' \91              '\\$y(x)=\\$$\\sqrt(16)\\$$\\$' \92              '</span>'93        self.tag_test(template, context, out)94    def test__parse_math_is_true_normal_text_then_block_tag(self):95        template = '{% latexify test_text parse_math=True %}'96        context = {'test_text':97                   'The following math eq: \$$y(x)=\sqrt(16)\$$ is complete'}98        output = '<span class="django-latexify text">' \99                 'The following math eq: ' \100                 '<span class="django-latexify math block">' \101                 'y(x)=\\sqrt(16)</span>' \102                 ' is complete</span>'103        self.tag_test(template, context, output)104    def test__parse_math_is_true_normal_text_then_inline_tag(self):105        template = '{% latexify test_text parse_math=True %}'106        context = {'test_text':107                   'The following math eq: \$y(x)=\sqrt(16)\$ is complete'}108        output = '<span class="django-latexify text">' \109                 'The following math eq: ' \110                 '<span class="django-latexify math inline">' \111                 'y(x)=\\sqrt(16)</span>' \112                 ' is complete</span>'113        self.tag_test(template, context, output)114    def test__both_inline_and_block_args_are_true(self):115        template = '{% latexify test_text math_inline=True math_block=True %}'116        context = {'test_text':117                   'The following math eq: \$y(x)=\sqrt(16)\$ is complete'}118        output = '<span class="django-latexify math inline">' \119                 'The following math eq: ' \120                 '\\$y(x)=\\sqrt(16)\\$ is complete' \121                 '</span>'122        self.tag_test(template, context, output)123    def test__math_block_set_true(self):124        template = '{% latexify test_text math_block=True %}'125        context = {'test_text':126                   'The following math eq: \$$y(x)=\sqrt(16)\$$ is complete'}127        output = '<span class="django-latexify math block">' \128                 'The following math eq: ' \129                 '\\$$y(x)=\\sqrt(16)\\$$ ' \130                 'is complete</span>'131        self.tag_test(template, context, output)132    def test__latex_css_is_specified(self):133        template = '{% latexify test_text latex_css="my_css_class" %}'134        context = {'test_text':135                   'Hello world'}136        output = '<span class="django-latexify my_css_class">' \137                 'Hello world' \138                 '</span>'139        self.tag_test(template, context, output)140    def test__value_from_setting(self):141        template = '{% value_from_settings "LATEX_MATH_INLINE_CSS_CLASS" %}'142        context = {}143        output = 'django-latexify math inline'144        self.tag_test(template, context, output)145    def test__value_from_setting_no_arg(self):146        with self.assertRaises(TemplateSyntaxError):147            template = '{% value_from_settings %}'148            context = {}149            output = ''...sax.py
Source:sax.py  
...7        self.__cur_attrs = {}8        self.__file_ast = VerilogFileAST()9        self.__cur_ast = None10        self.scanner = None11    def __tag_test(self, *args, back=False):12        if back:13            slice_pos = len(self.__tag_stack) - len(args)14            return self.__tag_stack[slice_pos:] == list(args)15        else:16            return self.__tag_stack[:len(args)] == list(args)17    def __attr_test(self, name, value=None):18        name = self.__prefix + name19        if not value:20            return self.__cur_attrs.get(name)21        else:22            return self.__cur_attrs[name] == value23    def start_element(self, name: str, attrs: dict):24        tag_test = self.__tag_test25        attr_test = self.__attr_test26        if name.startswith(self.__prefix):27            self.__tag_stack.append(name[len(self.__prefix):])28            self.__cur_attrs = attrs29            if tag_test('design', 'adHocConnections', 'adHocConnection'):30                if tag_test('externalPortReference', back=True):31                    port_name = attr_test('portRef')32                    if self.__file_ast.ports[port_name].direction == 'in':33                        self.__cur_ast.reference = port_name34                    else:   # out & inout35                        assign = VerilogAssignAST()36                        assign.name = port_name37                        assign.reference = self.__cur_ast.name38                        self.__file_ast.assigns.append(assign)39                if tag_test('internalPortReference', back=True):40                    con_ast = VerilogIOConnectionAST()41                    con_ast.port_name = attr_test('portRef')42                    con_ast.wire_name = self.__cur_ast.name43                    mod_ref = attr_test('componentRef')44                    mod_ast = self.__file_ast.modules[mod_ref]45                    mod_ast.connections.append(con_ast)46                    bus = self.scanner.get_bus(mod_ast.module_name, con_ast.port_name)47                    if self.__cur_ast.bus != bus:48                        if self.__cur_ast.bus:49                            print('warning: bus mismatch in wire "%s, %s" '50                                  'connected to port "%s, %s" of module '51                                  '"%s"' % \52                                  (self.__cur_ast.name, str(self.__cur_ast.bus),53                                  con_ast.port_name, str(bus), mod_ast.module_name))54                        self.__cur_ast.bus = bus55    def end_element(self, name: str):56        tag_test = self.__tag_test57        if name.startswith(self.__prefix):58            if tag_test('component', 'model', 'ports', 'port', back=True):59                self.__file_ast.ports[self.__cur_ast.name] = self.__cur_ast60                self.__cur_ast = None61            elif tag_test('design', 'componentInstances', 'componentInstance', back=True):62                self.__file_ast.modules[self.__cur_ast.instance_name] = self.__cur_ast63                self.__cur_ast = None64            elif tag_test('design', 'adHocConnections', 'adHocConnection', back=True):65                self.__file_ast.wires.append(self.__cur_ast)66                self.__cur_ast = None67            self.__tag_stack.pop()68    def char_data(self, text: str):69        tag_test = self.__tag_test70        attr_test = self.__attr_test71        try:72            if tag_test('component', 'name'):73                self.__file_ast.module_name = text74            elif tag_test('component', 'model', 'ports', 'port'):75                self.__cur_ast = self.__cur_ast or VerilogPortAST()76                if tag_test('name', back=True):77                    self.__cur_ast.name = text78                elif tag_test('wire', 'direction', back=True):79                    self.__cur_ast.direction = text80                elif tag_test('wire', 'vector', 'left', back=True):81                    self.__cur_ast.bus[0] = int(text)82                elif tag_test('wire', 'vector', 'right', back=True):83                    self.__cur_ast.bus[1] = int(text)84            elif tag_test('design', 'componentInstances', 'componentInstance'):85                self.__cur_ast = self.__cur_ast or VerilogModuleAST()86                if tag_test('instanceName', back=True):87                    self.__cur_ast.instance_name = text88                elif tag_test('configurableElementValues',89                        'configurableElementValue', back=True):90                    if attr_test('referenceId', 'bd:referenceName'):91                        # TODO: an inappropriate implementation92                        if not self.__cur_ast.module_name:93                            self.__cur_ast.module_name = text94                        else:95                            self.__cur_ast.module_name += text96            elif tag_test('design', 'adHocConnections', 'adHocConnection'):97                self.__cur_ast = self.__cur_ast or VerilogWireAST()98                if tag_test('name', back=True):99                    # TODO: an inappropriate implementation100                    if not self.__cur_ast.name:101                        self.__cur_ast.name = text.lower()102                    else:103                        self.__cur_ast.name += text.lower()104        except IndexError:105            pass106    107    def generate(self, bd_name):108        content = self.__file_ast.generate()...SentimentAnalysisBaseOnMachine.py
Source:SentimentAnalysisBaseOnMachine.py  
1#coding=utf-82import feature3import pickle4import nltk5import sklearn6from nltk.classify.scikitlearn import SklearnClassifier7from sklearn.svm import SVC, LinearSVC, NuSVC8from sklearn.naive_bayes import MultinomialNB, BernoulliNB9from sklearn.linear_model import LogisticRegression10from sklearn.metrics import accuracy_score11def pos_features(feature_extraction_method, pos, best_words):12    posFeatures = []13    for i in pos:14        posWords = [feature_extraction_method(i, best_words),'pos'] #ä¸ºç§¯æææ¬èµäº"pos"15        posFeatures.append(posWords)16    return posFeatures17def test_pos_features(feature_extraction_method, pos, best_words):18    posFeatures = []19    for i in pos:20        posWords = [feature_extraction_method(i, best_words)] #ä¸ºç§¯æææ¬èµäº"pos"21        posFeatures.append(posWords)22    return posFeatures23def neg_features(feature_extraction_method, neg, best_words):24    negFeatures = []25    for j in neg:26        negWords = [feature_extraction_method(j, best_words),'neg'] #ä¸ºæ¶æææ¬èµäº"neg"27        negFeatures.append(negWords)28    return negFeatures29def test_neg_features(feature_extraction_method, neg, best_words):30    negFeatures = []31    for j in neg:32        negWords = [feature_extraction_method(j, best_words)] #ä¸ºæ¶æææ¬èµäº"neg"33        negFeatures.append(negWords)34    return negFeatures35def score(classifier, trainSet, test, tag_test):36    classifier = SklearnClassifier(classifier) #å¨nltk ä¸ä½¿ç¨scikit-learn çæ¥å£37    classifier.train(trainSet) #è®ç»åç±»å¨38    pred = classifier.classify_many(test) #对å¼åæµè¯éçæ°æ®è¿è¡åç±»ï¼ç»åºé¢æµçæ ç¾39    return accuracy_score(tag_test, pred) #对æ¯åç±»é¢æµç»æåäººå·¥æ æ³¨çæ£ç¡®ç»æï¼ç»åºåç±»å¨å确度40'''41file_name_pos = 'source/pos.pkl'.decode('utf-8')42file_name_neg = 'source/neg.pkl'.decode('utf-8')43pos_review = pickle.load(open(file_name_pos,'r'))44neg_review = pickle.load(open(file_name_neg,'r'))45pos = pos_review46neg = neg_review47word_scores = feature.create_word_bigram_scores() #使ç¨è¯ååè¯æé
ä½ä¸ºç¹å¾48best_words = feature.find_best_words(word_scores, 1500) #ç¹å¾ç»´åº¦150049posFeatures = pos_features(feature.best_word_features, pos, best_words)50negFeatures = neg_features(feature.best_word_features, neg, best_words)51trainSet = posFeatures[:800] + negFeatures[:800] #使ç¨äºæ´å¤æ°æ®52testSet = posFeatures[800:900] + negFeatures[800:900]53test, tag_test = zip(*testSet)54print final_score(BernoulliNB())55'''56dimension = ['500','1000','1500','2000','2500','3000']57file_name_pos = 'source/pos.pkl'.decode('utf-8')58file_name_neg = 'source/neg.pkl'.decode('utf-8')59pos_review = pickle.load(open(file_name_pos,'r'))60neg_review = pickle.load(open(file_name_neg,'r'))61pos = pos_review62neg = neg_review63for d in dimension:64    word_scores = feature.create_word_bigram_scores()65    best_words = feature.find_best_words(word_scores, int(d))66    posFeatures = pos_features(feature.best_word_features, pos, best_words)67    negFeatures = neg_features(feature.best_word_features, neg, best_words)68    trainSet = posFeatures[:800]+negFeatures[:800]69    testSet = posFeatures[800:900]+negFeatures[800:900]70    test, tag_test = zip(*testSet)71    #print 'Feature number %f' %d72    print 'BernoulliNB`s accuracy is %f' %score(BernoulliNB(), trainSet, test, tag_test)73    print 'MultinomiaNB`s accuracy is %f' %score(MultinomialNB(), trainSet, test, tag_test)74    print 'LogisticRegression`s accuracy is %f' %score(LogisticRegression(), trainSet, test, tag_test)75    print 'SVC`s accuracy is %f' %score(SVC(), trainSet, test, tag_test)76    print 'LinearSVC`s accuracy is %f' %score(LinearSVC(), trainSet, test, tag_test)77    print 'NuSVC`s accuracy is %f' %score(NuSVC(), trainSet, test, tag_test)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
