for in documentsallcaps append(np sum([ isupper(for in split(if len( )> ])exclamation append( count("!")question append( count("?")hashtag append( count("#")mentioning append( count("@")result np array([obj_valpos_valneg_valnounsadjectivesverbsadverbsallcapsexclamationquestionhashtagmentioning] return result putting everything together neverthelessusing these linguistic features in isolation without the words themselves will not take us very far thereforewe have to combine tfidfvectorizer with the linguistic features this can be done with scikit-learn' featureunion class it is initialized the same way as pipelinebut instead of evaluating the estimators in sequence and each passing the output of the previous one to the next onefeatureunion does it in parallel and joins the output vectors afterwardsdef create_union_model(params=none)def preprocessor(tweet)tweet tweet lower(for in emo_repl_ordertweet tweet replace(kemo_repl[ ]for rrepl in re_repl iteritems()tweet re sub(rrepltweetreturn tweet replace("-""replace(" ""tfidf_ngrams tfidfvectorizer(preprocessor=preprocessoranalyzer="word"ling_stats linguisticvectorizer(all_features featureunion([('ling'ling_stats)('tfidf'tfidf_ngrams)]clf multinomialnb(