<s> import pickle <EOL> import numpy as np <EOL> from sklearn . feature_extraction . text import CountVectorizer <EOL> from sklearn . feature_extraction . text import TfidfTransformer , TfidfVectorizer <EOL> from sklearn . linear_model import SGDClassifier , SGDRegressor <EOL> from sklearn . metrics import mean_squared_error , mean_absolute_error <EOL> from sklearn . svm import LinearSVC , SVC <EOL> from sklearn . ensemble import RandomForestClassifier <EOL> TRAIN_FILE = "<STR_LIT>" <EOL> DEV_FILE = "<STR_LIT>" <EOL> TEST_FILE = "<STR_LIT>" <EOL> with open ( TRAIN_FILE ) as file : <EOL> [ train_reviews , train_labels ] = pickle . load ( file ) <EOL> with open ( DEV_FILE ) as file : <EOL> [ dev_reviews , dev_labels ] = pickle . load ( file ) <EOL> with open ( TEST_FILE ) as file : <EOL> [ test_reviews , test_labels ] = pickle . load ( file ) <EOL> ngram_range = ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> count_vect = CountVectorizer ( ngram_range = ngram_range , stop_words = "<STR_LIT>" , max_features = <NUM_LIT> ) <EOL> X_train_counts = count_vect . fit_transform ( train_reviews ) <EOL> tfidf_transformer = TfidfTransformer ( use_idf = True ) . fit ( X_train_counts ) <EOL> X = tfidf_transformer . transform ( X_train_counts ) <EOL> print "<STR_LIT>" <EOL> classifier = RandomForestClassifier ( ) . fit ( X . toarray ( ) , train_labels ) <EOL> train_accuracy = classifier . score ( X . toarray ( ) , train_labels ) <EOL> print "<STR_LIT>" % train_accuracy <EOL> X_dev_counts = count_vect . transform ( dev_reviews ) <EOL> X_dev_tfidf = tfidf_transformer . transform ( X_dev_counts ) <EOL> dev_accuracy = classifier . score ( X_dev_tfidf . toarray ( ) , dev_labels ) <EOL> print "<STR_LIT>" + str ( dev_accuracy ) </s>
