From d4b396f3bebea910c1f1f8aaf84316ec29f27659 Mon Sep 17 00:00:00 2001 From: Maciej Sobkowiak Date: Wed, 12 May 2021 20:29:37 +0200 Subject: [PATCH] Working on bayes2 --- bayes2.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/bayes2.py b/bayes2.py index 85c6dd3..6d16ed8 100644 --- a/bayes2.py +++ b/bayes2.py @@ -1,7 +1,11 @@ import pandas as pd import numpy as np 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) 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: for l in f: line = l.decode('UTF-8').replace("\n", "").split("\t") - y_train.append(line[0]) - X_train.append(line[1:]) + y_train.append(int(line[0])) + X_train.append(str(line[1:])) -X_train = np.asanyarray(X_train) -y_train = np.asanyarray(y_train) +# Convert to unified types +X_train = np.asarray(X_train) +y_train = np.asarray(y_train) X_dev = dev[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)