-
Notifications
You must be signed in to change notification settings - Fork 4
/
problem.py
48 lines (38 loc) · 1.32 KB
/
problem.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
import os
import pandas as pd
import rampwf as rw
from sklearn.model_selection import StratifiedShuffleSplit
problem_title = 'Pollenating insect classification (403 classes)'
_target_column_name = 'class'
_prediction_label_names = range(0, 403)
# A type (class) which will be used to create wrapper objects for y_pred
Predictions = rw.prediction_types.make_multiclass(
label_names=_prediction_label_names)
# An object implementing the workflow
workflow = rw.workflows.ImageClassifier(
test_batch_size=16,
chunk_size=256,
n_jobs=8,
n_classes=len(_prediction_label_names),
)
score_types = [
rw.score_types.Accuracy(name='accuracy', precision=3),
rw.score_types.NegativeLogLikelihood(name='nll', precision=3),
rw.score_types.F1Above(name='f170', threshold=0.7, precision=3),
]
def get_cv(folder_X, y):
_, X = folder_X
cv = StratifiedShuffleSplit(n_splits=1, test_size=0.2, random_state=57)
return cv.split(X, y)
def _read_data(path, f_name):
df = pd.read_csv(os.path.join(path, 'data', f_name))
X = df['id'].values
y = df['class'].values
folder = os.path.join(path, 'data', 'imgs')
return (folder, X), y
def get_test_data(path='.'):
f_name = 'test.csv'
return _read_data(path, f_name)
def get_train_data(path='.'):
f_name = 'train.csv'
return _read_data(path, f_name)