in [ ]from sklearn feature_extraction text import countvectorizertfidfvectorizer build bow features on train reviews cv countvectorizer(binary=falsemin_df= max_df= ngram_range=( , )cv_train_features cv fit_transform(norm_train_reviewsbuild tfidf features on train reviews tv tfidfvectorizer(use_idf=truemin_df= max_df= ngram_range=( , )sublinear_tf=truetv_train_features tv fit_transform(norm_train_reviewstransform test reviews into features cv_test_features cv transform(norm_test_reviewstv_test_features tv transform(norm_test_reviewsprint('bow model:train features shape:'cv_train_features shapetest features shape:'cv_test_features shapeprint('tfidf model:train features shape:'tv_train_features shapetest features shape:'tv_test_features shapebow model:train features shape( test features shape( tfidf model:train features shape( test features shape( we take into account word as well as bi-grams for our feature-sets we can now use some traditional supervised machine learning algorithms which work very well on text classification we recommend using logistic regressionsupport vector machinesand multinomial naive bayes models when you work on your own datasets in the future in this we built models using logistic regression as well as svm the following snippet helps initialize these classification model estimators in [ ]from sklearn linear_model import sgdclassifierlogisticregression lr logisticregression(penalty=' 'max_iter= = svm sgdclassifier(loss='hinge'n_iter= without going into too many theoretical complexitiesthe logistic regression model is supervised linear machine learning model used for classification regardless of its name in this modelwe try to predict the probability that given movie review will belong to one of the discrete classes (binary classes in our scenariothe function used by the model for learning is represented here positive ( negative ( where the model tries to predict the sentiment class using the feature vector and which is - popularly known as the sigmoid function or logistic function or the logit function the main objective of this model is to search for an optimal value of such that probability of the positive sentiment class is maximum when the feature vector is for positive movie review and small when it is for negative movie review the logistic function helps model the probability to describe the final prediction class the optimal value of can be obtained by minimizing an appropriate cost\loss function using standard methods like