Compare commits
No commits in common. "master" and "master" have entirely different histories.
30
bayes.py
30
bayes.py
@ -1,30 +0,0 @@
|
|||||||
import numpy as np
|
|
||||||
import pandas as pd
|
|
||||||
import gzip
|
|
||||||
from sklearn.naive_bayes import MultinomialNB
|
|
||||||
from sklearn.feature_extraction.text import CountVectorizer
|
|
||||||
|
|
||||||
bayes = MultinomialNB()
|
|
||||||
vec_q = CountVectorizer()
|
|
||||||
|
|
||||||
with gzip.open('./train/train.tsv.gz', 'rb') as f:
|
|
||||||
train = pd.read_csv(f, error_bad_lines=False, header=None, sep="\t")
|
|
||||||
dev = pd.read_csv("./dev-0/in.tsv", error_bad_lines=False, header=None, sep="\t")
|
|
||||||
test = pd.read_csv("./test-A/in.tsv", error_bad_lines=False, header=None, sep="\t")
|
|
||||||
|
|
||||||
# model
|
|
||||||
X_train, y_train = train[0].astype(str).tolist(), train[1].astype(str).tolist()
|
|
||||||
y_train=vec_q.fit_transform(y_train)
|
|
||||||
bayes.fit(y_train, X_train)
|
|
||||||
|
|
||||||
# dev
|
|
||||||
X_dev = dev[0].astype(str).tolist()
|
|
||||||
y_dev = vec_q.transform(X_dev)
|
|
||||||
dev_pred = bayes.predict(y_dev)
|
|
||||||
pd.DataFrame(dev_pred).to_csv('./dev-0/out.tsv', sep='\t', index=False, header=False)
|
|
||||||
|
|
||||||
# test
|
|
||||||
X_test = train[0].astype(str).tolist()
|
|
||||||
y_test = vec_q.transform(X_test)
|
|
||||||
test_pred = bayes.predict(y_test)
|
|
||||||
pd.DataFrame(test_pred).to_csv('./test-A/out.tsv', sep='\t', index=False, header=False)
|
|
5452
dev-0/out.tsv
5452
dev-0/out.tsv
File diff suppressed because it is too large
Load Diff
98129
test-A/out.tsv
98129
test-A/out.tsv
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user