Esempio n. 1
0
    print "SGD Classifier"
    sgd = SGDTextClassifier(train_reviews,
                            train_labels,
                            test_texts=test_reviews,
                            test_labels=test_labels)
    #train_error = sgd.get_training_error()
    #test_error = sgd.get_test_error()
    #print "Training error: " + str(train_error)
    #print "Test error: " + str(test_error)
    sgd.set_bag_of_ngrams()
    sgd.grid_search_cv(verbose=0, n_jobs=4)

    print "Logistic classifier"
    sgd = LogisticClassifier()
    sgd.set_training_data(train_reviews, train_labels)
    sgd.set_test_data(test_reviews, test_labels)
    sgd.set_bag_of_ngrams()

    sgd.train()
    train_error = sgd.get_training_error()
    test_error = sgd.get_test_error()
    print "Training error: " + str(train_error)
    print "Test error: " + str(test_error)

    print "SVM classifier"
    sgd = SVMClassifier()
    sgd.set_training_data(train_reviews, train_labels)
    sgd.set_test_data(test_reviews, test_labels)
    sgd.set_bag_of_ngrams()
Esempio n. 2
0
    print "Test error: " + str(test_error)

    print "SGD Classifier"
    sgd = SGDTextClassifier(train_reviews, train_labels,
                            test_texts=test_reviews, test_labels=test_labels)
    #train_error = sgd.get_training_error()
    #test_error = sgd.get_test_error()
    #print "Training error: " + str(train_error)
    #print "Test error: " + str(test_error)
    sgd.set_bag_of_ngrams()
    sgd.grid_search_cv(verbose=0, n_jobs=4)


    print "Logistic classifier"
    sgd = LogisticClassifier()
    sgd.set_training_data(train_reviews, train_labels)
    sgd.set_test_data(test_reviews, test_labels)
    sgd.set_bag_of_ngrams()

    sgd.train()
    train_error = sgd.get_training_error()
    test_error = sgd.get_test_error()
    print "Training error: " + str(train_error)
    print "Test error: " + str(test_error)

    print "SVM classifier"
    sgd = SVMClassifier()
    sgd.set_training_data(train_reviews, train_labels)
    sgd.set_test_data(test_reviews, test_labels)
    sgd.set_bag_of_ngrams()