import pandas as pd
train=pd.read_csv("kaggle-sentiment/train.tsv", delimiter='\t')
y=train['Sentiment'].values
X=train['Phrase'].values
pred_vec = bigram_tv_v3 # 60.4
test = pd.read_csv("kaggle-sentiment/test.tsv", delimiter='\t')
k_id = test['PhraseId']
k_text = test['Phrase']
# k_vec = bigram_tv_v3.transform(k_text)
# k_vec
def get_kaggle_test_train_vec(X,y,vectorizer):
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=None, random_state=0)
X_train_vec = vectorizer.fit_transform(X_train)
# X_test_vec = vectorizer.transform(X_test)
return X_train_vec, y_train,
def do_the_kaggle(X,y,vec):
X_train_vec, y_train = get_kaggle_test_train_vec(X,y,vec)
svm_clf = LinearSVC(C=1)
k_vec = pred_vec.transform(k_text)
print(len(X), X_train_vec.shape, k_vec.shape)
prediction = svm_clf.fit(X_train_vec,y_train).predict(k_vec)
kaggle_submission = zip(k_id, prediction)
outf=open('kaggle_submission_linearSVC_v8.csv', 'w')
outf.write('PhraseId,Sentiment\n')
for x, value in enumerate(kaggle_submission): outf.write(str(value[0]) + ',' + str(value[1]) + '\n')
outf.close()
print('prediction complete')
do_the_kaggle(X,y,pred_vec)