-
Notifications
You must be signed in to change notification settings - Fork 2
/
submission.py
54 lines (44 loc) · 2.08 KB
/
submission.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import csv
def create_csv_submission(ids, y_pred, name):
"""
Creates an output file in .csv format for submission to Kaggle or AIcrowd
Arguments: ids (event ids associated with each prediction)
y_pred (predicted class labels)
name (string name of .csv output file to be created)
"""
with open(name, 'w') as csvfile:
fieldnames = ['Id', 'Prediction']
writer = csv.DictWriter(csvfile, delimiter=",", fieldnames=fieldnames)
writer.writeheader()
for r1, r2 in zip(ids, y_pred):
writer.writerow({'Id':int(r1),'Prediction':int(r2)})
def make_submission_glove(test_x, name, model):
"""
Creates the submission when the embeddings used were glove
Inputs :
- test_x (ndarray) : array containing the embeddings og the tweets used for testing
- name (string) : name given for the submission of the file
- model (sklearn.Model) : model to use for this submission
"""
#predict rather the tweets are positive or negative
predictions_test = model.predict(test_x)
#creates the ids of the test
ids = np.arange(test_x.shape[0])+1
#changes labels of 0 to -1 for tweets predicted as negative
predictions_test[predictions_test==0] = -1
create_csv_submission(ids, predictions_test, PATH_DATA + 'submissions/output_' + name + '.csv' )
def make_submission_tfidf(test_x, name, model):
"""
Creates the submission when the embeddings used were Tf-Idf
Inputs :
- test_x (ndarray) : contains the embeddings of the tweets to predict
- name (string) : name for the submission file
- model (sklearn.Model) : model to use for the prediction
"""
#predict rather the tweets are positive or negative
predictions_test = model.predict(test_x)
#creates the ids for the test
ids = np.arange(test_x.shape[1])+1
#changes labels of 0 to -1 for tweets predicted as negative
predictions_test[predictions_test==0] = -1
create_csv_submission(ids, predictions_test, PATH_DATA + 'submissions/output_' + name + '.csv' )