Kaggle competition: Bag of Words Meets Bags of Popcorn
lgb = make_pipeline(GridSearchCV(LGBMRegressor(verbose_eval=False,random_state=1),param_lgb,
cv=10, scoring = RMSLE))<train_model>
train = pd.read_csv(".. /input/labeledTrainData.tsv", header = 0, delimiter = '\t')
 def review_to_words(raw_review):
review_text = BeautifulSoup(raw_review, features="html5lib" ).get_text()
letters_only = re.sub("[^a-zA-Z]", " ", review_text)
 words = letters_only.lower().split()
stops = set(stopwords.words("english"))
meaningful_words = [w for w in words if not w in stops]
element = " ".join(meaningful_words)
 return(element)
 num_reviews = train["review"].size
clean_train_reviews = []
def fn(raw_review):
element = review_to_words(raw_review)
 return(element)
 print("Cleaning the Reviews...")
 pool = Pool()
clean_train_reviews = pool.map(fn,train["review"])
 pool.close()
pool.join()
print("The length of the Cleaned Reviews is "+str(len(clean_train_reviews)) )
lgb.fit(X_train,y_train )<predict_on_test>
vectorizer = CountVectorizer(analyzer = "word", \
tokenizer = None, \
preprocessor = None, \
stop_words = None, \
max_features = 1500)
 train_data_features = vectorizer.fit_transform(clean_train_reviews)
 print("Creating Features...")
 train_data_features = train_data_features.toarray()
print("Features Created" )
lgb_yhat = lgb.predict(X_val)
 s_lgb = rmsle_score(lgb_yhat,y_val)
 s_lgb<predict_on_test>
print("Going to Train the Data Features")
 print("The length of the array is "+str(len(train_data_features)) )
pred_lgb = lgb.predict(new_test )<define_variables>
clf = SVC(gamma='auto',cache_size=12000,max_iter=-1)
 print("Training the data set...")
 clf = clf.fit(train_data_features, train["sentiment"])
 print("Training Completed" )
list_scores = [s_lasso, s_Enet, s_RF,s_GB,s_lgb]
list_regressors = ['Lasso','Enet','RF','GB','lgb']<define_variables>
test = pd.read_csv(".. /input/testData.tsv", header=0, delimiter="\t", \
quoting=3)
 print("Reading the Test Data...")
 num_reviews = len(test["review"])
 clean_test_reviews = []
print("Total number of reviews is "+str(num_reviews))
pool = Pool()
clean_test_reviews = pool.map(fn,test["review"])
 pool.close()
pool.join()
print("Cleaning of the Test Reviews is Completed!!")
 print("The length of the cleaned test reviews is "+str(len(clean_test_reviews)))
<create_dataframe><EOS> 
test_data_features = vectorizer.transform(clean_test_reviews)
 print("Making the features from the Test Reviews...")
 test_data_features = test_data_features.toarray()
print("Going to predict the Test Features...")
 result = clf.predict(test_data_features)
 print("Prediction Completed!!")
 output = pd.DataFrame(data={"id":test["id"], "sentiment":result})
 print("Saving the Predictions to the File")
 output.to_csv("results.csv", index=False, quoting=3 )