projekt-uma/svm.ipynb
2021-07-05 13:19:12 +02:00

3.0 KiB

import pandas as pd
import numpy as np
from nltk.tokenize import word_tokenize
from nltk import pos_tag
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
from sklearn.preprocessing import LabelEncoder
from collections import defaultdict
from nltk.corpus import wordnet as wn
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn import model_selection, naive_bayes, svm
from sklearn.metrics import accuracy_score
from sklearn.pipeline import make_pipeline
with open("train/in.tsv") as f:
    x_train = f.readlines()

with open("train/expected.tsv") as f:
    y_train = f.readlines()
np.random.seed(500)
with open("dev-0/in.tsv") as f:
    x_dev = f.readlines()
y_train = LabelEncoder().fit_transform(y_train)
y_train
array([1, 0, 0, ..., 0, 0, 1])
pipeline = make_pipeline(TfidfVectorizer(),svm.SVC())
model = pipeline.fit(x_train, y_train)
prediction = model.predict(x_dev)
np.savetxt("svm/out.tsv", prediction, fmt='%d')