达观杯baseline
简单baseline
import pandas as pd, numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn import svm
column = "word_seg"
train = pd.read_csv('train_set.csv')
test = pd.read_csv('test_set.csv')
test_id = test["id"].copy()
vec = TfidfVectorizer(ngram_range=(1,2),min_df=3, max_df=0.9,use_idf=1,smooth_idf=1, sublinear_tf=1)
train_term_doc = vec.fit_transform(train[column])
test_term_doc = vec.transform(test[column])
fid=open('baseline.csv','w')
y=train["class"]
lin_clf = svm.LinearSVC()
lin_clf.fit(train_term_doc,y)
preds = lin_clf.predict(test_term_doc)
fid.write("id,class"+"\n")
for item in enmurate(preds):
fid0.write(str(i)+","+str(item)+"\n")
fid.close()
score: 0.77788