-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocessing.py
More file actions
153 lines (129 loc) · 5.18 KB
/
preprocessing.py
File metadata and controls
153 lines (129 loc) · 5.18 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#
# Copyright 2019 GridGain Systems, Inc. and Contributors.
#
# Licensed under the GridGain Community Edition License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Normalization preprocessing with Ignite ML (local).
from sklearn.datasets import make_classification
from ggml.preprocessing import NormalizationTrainer
x, y = make_classification()
normalizer = NormalizationTrainer().fit(x)
normalizer.transform(x)
# Normalization preprocessing with Ignite ML (cache).
import numpy as np
from sklearn.datasets import make_classification
from ggml.core import Ignite
from ggml.preprocessing import NormalizationTrainer
with Ignite("example-ignite.xml") as ignite:
cache = ignite.create_cache("my-cache")
for i, row in enumerate(np.column_stack(make_classification())):
cache.put(i, row)
normalizer = NormalizationTrainer().fit(cache)
cache_transformed = cache.transform(normalizer)
head = cache_transformed.head()
head
# Binarization preprocessing with Ignite ML (local).
from sklearn.datasets import make_classification
from ggml.preprocessing import BinarizationTrainer
x, y = make_classification()
binarizer = BinarizationTrainer(threshold=0.5).fit([[]])
binarizer.transform(x)
# Binarization preprocessing with Ignite ML (cache).
import numpy as np
from sklearn.datasets import make_classification
from ggml.core import Ignite
from ggml.preprocessing import BinarizationTrainer
with Ignite("example-ignite.xml") as ignite:
cache = ignite.create_cache("my-cache")
for i, row in enumerate(np.column_stack(make_classification())):
cache.put(i, row)
binarizer = BinarizationTrainer().fit(cache)
cache_transformed = cache.transform(binarizer)
head = cache_transformed.head()
head
# Imputing preprocessing with Ignite ML (local).
from sklearn.datasets import make_classification
from ggml.preprocessing import ImputerTrainer
x = [[None, 1, 1], [2, None, 2]]
imputer = ImputerTrainer().fit(x)
imputer.transform(x)
# Imputing preprocessing with Ignite ML (cache).
import numpy as np
from sklearn.datasets import make_classification
from ggml.core import Ignite
from ggml.preprocessing import ImputerTrainer
with Ignite("example-ignite.xml") as ignite:
cache = ignite.create_cache("my-cache")
for i, row in enumerate([[None, 1, 1, 0], [2, None, 2, 0]]):
cache.put(i, row)
imputer = ImputerTrainer().fit(cache)
cache_transformed = cache.transform(imputer)
head = cache_transformed.head()
head
# One-Hot-Encoding preprocessing with Ignite ML (local).
from sklearn.datasets import make_classification
from ggml.preprocessing import EncoderTrainer
x = [[1, 2, 0], [2, 1, 0]]
encoder = EncoderTrainer(encoded_features=[0, 1]).fit(x)
encoder.transform(x)
# One-Hot-Encoding preprocessing with Ignite ML (cache).
import numpy as np
from sklearn.datasets import make_classification
from ggml.core import Ignite
from ggml.preprocessing import EncoderTrainer
with Ignite("example-ignite.xml") as ignite:
cache = ignite.create_cache("my-cache")
for i, row in enumerate([[1, 2, 0], [2, 1, 0]]):
cache.put(i, row)
encoder = EncoderTrainer(encoded_features=[0, 1]).fit(cache)
cache_transformed = cache.transform(encoder)
head = cache_transformed.head()
head
# MinMax scaling preprocessing with Ignite ML (local).
from sklearn.datasets import make_classification
from ggml.preprocessing import MinMaxScalerTrainer
x, y = make_classification()
scaler = MinMaxScalerTrainer().fit(x)
scaler.transform(x)
# MinMax scaling preprocessing with Ignite ML (cache).
import numpy as np
from sklearn.datasets import make_classification
from ggml.core import Ignite
from ggml.preprocessing import MinMaxScalerTrainer
with Ignite("example-ignite.xml") as ignite:
cache = ignite.create_cache("my-cache")
for i, row in enumerate(np.column_stack(make_classification())):
cache.put(i, row)
scaler = MinMaxScalerTrainer().fit(cache)
cache_transformed = cache.transform(scaler)
head = cache_transformed.head()
head
# MaxAbs scaling preprocessing with Ignite ML (local).
from sklearn.datasets import make_classification
from ggml.preprocessing import MaxAbsScalerTrainer
x, y = make_classification()
scaler = MaxAbsScalerTrainer().fit(x)
scaler.transform(x)
# MaxAbs scaling preprocessing with Ignite ML (cache).
import numpy as np
from sklearn.datasets import make_classification
from ggml.core import Ignite
from ggml.preprocessing import MaxAbsScalerTrainer
with Ignite("example-ignite.xml") as ignite:
cache = ignite.create_cache("my-cache")
for i, row in enumerate(np.column_stack(make_classification())):
cache.put(i, row)
scaler = MaxAbsScalerTrainer().fit(cache)
cache_transformed = cache.transform(scaler)
head = cache_transformed.head()
head