-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-bqml-Split_the_dataset.sql
113 lines (102 loc) · 1.78 KB
/
2-bqml-Split_the_dataset.sql
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
--created a fake uniqueID column to help with the random splitting
CREATE OR REPLACE TABLE
`ml-project-383113.accent.new_recognition_split` AS (
SELECT
GENERATE_UUID() AS UUID,
X1,
X2,
X3,
X4,
X5,
X6,
X7,
X8,
X9,
X10,
X11,
X12,
LANGUAGE
FROM
`ml-project-383113.accent.new_recognition`);
--Split the dataset into training and test sets
CREATE OR REPLACE TABLE
`ml-project-383113.accent.test_data`AS
SELECT
*
FROM
`ml-project-383113.accent.new_recognition_split`
WHERE
MOD(ABS(FARM_FINGERPRINT(UUID)), 5) = 0;
CREATE OR REPLACE TABLE
`ml-project-383113.accent.train_data` AS
SELECT
*
FROM
`ml-project-383113.accent.new_recognition_split`
WHERE
NOT UUID IN (
SELECT
DISTINCT UUID
FROM
`ml-project-383113.accent.test_data`);
--- \\ Extra // ---
--EXTRA: not used in this project, but the dataset can be divided into three as train, test and validation.
--If you want to use this as an extra, the code is:
CREATE OR REPLACE TABLE
accent.training_data AS
WITH DATA AS (
SELECT
*,
RAND() AS rand
FROM
`ml-project-383113.accent.new_recognition` ),
training_data AS (
SELECT
*
FROM
DATA
WHERE
rand < 0.6)
SELECT
*
FROM
training_data;
CREATE OR REPLACE TABLE
accent.validation_data AS
WITH DATA AS (
SELECT
*,
RAND() AS rand
FROM
`ml-project-383113.accent.new_recognition` ),
validation_data AS (
SELECT
*
FROM
DATA
WHERE
rand >= 0.6
AND rand < 0.8)
SELECT
*
FROM
validation_data;
CREATE OR REPLACE TABLE
accent.test_data AS
WITH DATA AS (
SELECT
*,
RAND() AS rand
FROM
`ml-project-383113.accent.new_recognition` ),
test_data AS (
SELECT
*
FROM
DATA
WHERE
rand >= 0.8)
SELECT
*
FROM
test_data;