-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
28 lines (21 loc) · 811 Bytes
/
utils.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
import errno
import os
import pandas as pd
from pybrain.datasets import ClassificationDataSet
def to_dataset(df, attributes, class_names, label):
# type: (pd.DataFrame, list, list, str) -> ClassificationDataSet
ds = ClassificationDataSet(len(attributes), 1, class_labels=class_names)
for i, row in df.iterrows():
input_row = [row[attr] for attr in attributes]
output_row = (row[label])
ds.addSample(input_row, output_row)
return ds
def to_xy(df, attributes, label):
# type: (pd.DataFrame, list, str) -> [pd.DataFrame, pd.DataFrame]
return df[attributes], df[label]
def make_sure_path_exists(path):
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise