Python* API Reference for Intel® Data Analytics Acceleration Library 2020 Update 1

zscore_dense_batch.py

1 # file: zscore_dense_batch.py
2 #===============================================================================
3 # Copyright 2014-2020 Intel Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #===============================================================================
17 
18 #
19 # ! Content:
20 # ! Python example of Z-score normalization algorithm.
21 # !*****************************************************************************
22 
23 #
24 
25 
26 #
27 
28 import os
29 import sys
30 
31 import daal.algorithms.normalization.zscore as zscore
32 from daal.data_management import DataSourceIface, FileDataSource
33 
34 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
35 if utils_folder not in sys.path:
36  sys.path.insert(0, utils_folder)
37 from utils import printNumericTable
38 
39 # Input data set parameters
40 datasetName = os.path.join('..', 'data', 'batch', 'normalization.csv')
41 
42 if __name__ == "__main__":
43 
44  # Retrieve the input data
45  dataSource = FileDataSource(datasetName,
46  DataSourceIface.doAllocateNumericTable,
47  DataSourceIface.doDictionaryFromContext)
48  dataSource.loadDataBlock()
49 
50  data = dataSource.getNumericTable()
51 
52  # Create an algorithm
53  algorithm = zscore.Batch(method=zscore.sumDense)
54 
55  # Set an input object for the algorithm
56  algorithm.input.set(zscore.data, data)
57 
58  # Compute Z-score normalization function
59  res = algorithm.compute()
60 
61  printNumericTable(data, "First 10 rows of the input data:", 10)
62  printNumericTable(res.get(zscore.normalizedData), "First 10 rows of the z-score normalization result:", 10)

For more complete information about compiler optimizations, see our Optimization Notice.