-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertingData.py
More file actions
38 lines (31 loc) · 1022 Bytes
/
ConvertingData.py
File metadata and controls
38 lines (31 loc) · 1022 Bytes
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
"""
:author: Ryan Nicholas
:date: February 15, 2020
:description: Convert data to be ready for training
"""
from sklearn.preprocessing import LabelEncoder
from keras.utils import to_categorical
import numpy as np
from pandas import DataFrame
class ConvertData():
def __init__(self, vals):
"""
Initialize Data
:param df:
"""
self.df = DataFrame(vals, columns=['index', 'label'])
def splitData(self):
"""
Split the data for the file
:return:
"""
# Get the x and y data
x = np.array(self.df.index.tolist())
y = np.array(self.df.label.tolist())
# Encode the classification labels
le = LabelEncoder()
yy = to_categorical(le.fit_transform(y))
# split the data
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, yy, test_size=0.2, random_state=42, train_size=0.8)
return (x_train, x_test, y_train, y_test)