s444421
This commit is contained in:
parent
97421a97ee
commit
c9207fce50
149134
dev-0/out.tsv
Normal file
149134
dev-0/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
77
run.py
Normal file
77
run.py
Normal file
@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
# In[208]:
|
||||
|
||||
|
||||
import pandas as pd
|
||||
import vowpalwabbit
|
||||
from sklearn import preprocessing
|
||||
|
||||
|
||||
# In[209]:
|
||||
|
||||
|
||||
vw = vowpalwabbit.Workspace('--oaa 20')
|
||||
|
||||
|
||||
# In[210]:
|
||||
|
||||
|
||||
X_train = pd.read_csv('train\in.tsv', sep='\t', usecols=[2], names=['text'])
|
||||
Y_train = pd.read_csv('train\expected.tsv', sep='\t', usecols=[0], names=['class'])
|
||||
|
||||
|
||||
# In[211]:
|
||||
|
||||
|
||||
Y_train['class'].unique()
|
||||
|
||||
|
||||
# In[212]:
|
||||
|
||||
|
||||
le = preprocessing.LabelEncoder()
|
||||
le.fit(['business', 'culture', 'lifestyle', 'news', 'opinion', 'removed', 'sport'])
|
||||
Y_train['class'] = le.fit_transform(Y_train['class'])
|
||||
|
||||
|
||||
# In[213]:
|
||||
|
||||
|
||||
for x, y in zip(X_train['text'], Y_train['class']):
|
||||
vw.learn(f'{y} | text:{x}')
|
||||
|
||||
|
||||
# In[216]:
|
||||
|
||||
|
||||
def make_prediction(path_in, path_out):
|
||||
test_set = pd.read_csv(path_in, sep='\t', usecols=[2], names=['text'])
|
||||
predictions = []
|
||||
for x in X_dev0['text']:
|
||||
predictions.append(vw.predict(f'| text:{x}'))
|
||||
predictions = le.inverse_transform(predictions)
|
||||
file = open(path_out, 'w')
|
||||
for pred in predictions:
|
||||
file.write(f'{pred}\n')
|
||||
file.close()
|
||||
|
||||
|
||||
# In[217]:
|
||||
|
||||
|
||||
make_prediction('dev-0\in.tsv', 'dev-0\out.tsv')
|
||||
|
||||
|
||||
# In[218]:
|
||||
|
||||
|
||||
make_prediction('test-A\in.tsv', 'test-A\out.tsv')
|
||||
|
||||
|
||||
# In[219]:
|
||||
|
||||
|
||||
make_prediction('test-B\in.tsv', 'test-B\out.tsv')
|
||||
|
149134
test-A/out.tsv
Normal file
149134
test-A/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
149134
test-B/out.tsv
Normal file
149134
test-B/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user