Working on bayes2
This commit is contained in:
parent
7ea61e7e1f
commit
d4b396f3be
20
bayes2.py
20
bayes2.py
@ -1,7 +1,11 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import gzip
|
import gzip
|
||||||
|
from sklearn.pipeline import make_pipeline
|
||||||
|
from sklearn.naive_bayes import MultinomialNB
|
||||||
|
from sklearn.feature_extraction.text import TfidfVectorizer
|
||||||
|
|
||||||
|
# Read data
|
||||||
dev = pd.read_table('dev-0/in.tsv', error_bad_lines=False, header=None)
|
dev = pd.read_table('dev-0/in.tsv', error_bad_lines=False, header=None)
|
||||||
test = pd.read_table('test-A/in.tsv', error_bad_lines=False, header=None)
|
test = pd.read_table('test-A/in.tsv', error_bad_lines=False, header=None)
|
||||||
|
|
||||||
@ -11,13 +15,19 @@ y_train = []
|
|||||||
with gzip.open('train/train.tsv.gz', 'r') as f:
|
with gzip.open('train/train.tsv.gz', 'r') as f:
|
||||||
for l in f:
|
for l in f:
|
||||||
line = l.decode('UTF-8').replace("\n", "").split("\t")
|
line = l.decode('UTF-8').replace("\n", "").split("\t")
|
||||||
y_train.append(line[0])
|
y_train.append(int(line[0]))
|
||||||
X_train.append(line[1:])
|
X_train.append(str(line[1:]))
|
||||||
|
|
||||||
X_train = np.asanyarray(X_train)
|
# Convert to unified types
|
||||||
y_train = np.asanyarray(y_train)
|
X_train = np.asarray(X_train)
|
||||||
|
y_train = np.asarray(y_train)
|
||||||
|
|
||||||
X_dev = dev[0].values
|
X_dev = dev[0].values
|
||||||
X_test = test[0].values
|
X_test = test[0].values
|
||||||
|
|
||||||
print(X_dev)
|
print(type(y_train[0]))
|
||||||
|
print(X_train[0])
|
||||||
|
|
||||||
|
# Create model
|
||||||
|
model = make_pipeline(TfidfVectorizer(), MultinomialNB())
|
||||||
|
model.fit(X_train, y_train)
|
||||||
|
Loading…
Reference in New Issue
Block a user