Deprecation Notice: With the introduction of daal4py, a package that supersedes PyDAAL, Intel is deprecating PyDAAL and will discontinue support starting with Intel® DAAL 2021 and Intel® Distribution for Python 2021. Until then Intel will continue to provide compatible pyDAAL pip and conda packages for newer releases of Intel DAAL and make it available in open source. However, Intel will not add the new features of Intel DAAL to pyDAAL. Intel recommends developers switch to and use daal4py.
Note: To find daal4py examples, refer to daal4py documentation or browse github repository.
30 import daal.algorithms.pca
as pca
31 import daal.algorithms.pca.transform
as pca_transform
32 from daal.data_management
import DataSourceIface, FileDataSource
34 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(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 from daal.data_management
import NumericTable
40 datasetName = os.path.join(
'..',
'data',
'batch',
'pca_transform.csv')
42 if __name__ ==
"__main__":
45 dataSource = FileDataSource(datasetName,
46 DataSourceIface.doAllocateNumericTable,
47 DataSourceIface.doDictionaryFromContext)
48 dataSource.loadDataBlock()
49 data = dataSource.getNumericTable()
52 algorithm = pca.Batch(fptype=np.float64,method=pca.svdDense)
55 algorithm.input.setDataset(pca.data, data)
64 algorithm.parameter.resultsToCompute = pca.mean | pca.variance | pca.eigenvalue;
67 res = algorithm.compute()
69 printNumericTable(res.get(pca.eigenvalues),
"Eigenvalues:")
70 printNumericTable(res.get(pca.eigenvectors),
"Eigenvectors:")
72 eigenvaluesT = res.get(pca.eigenvalues)
73 printNumericTable(eigenvaluesT,
"Eigenvalues kv:")
75 meansT = res.get(pca.means)
76 printNumericTable(meansT,
"Means kv:")
79 variancesT = res.get(pca.variances)
80 printNumericTable(variancesT,
"Variances kv:")
83 tralgorithm = pca_transform.Batch(fptype=np.float64)
86 tralgorithm.parameter.nComponents = 2
89 tralgorithm.input.setTable(pca_transform.data, data)
92 tralgorithm.input.setTable(pca_transform.eigenvectors, res.get(pca.eigenvectors))
95 tralgorithm.input.setCollection(pca_transform.dataForTransform, res.getCollection(pca.dataForTransform))
98 trres = tralgorithm.compute()
100 printNumericTable(trres.get(pca.transform.transformedData),
"Transformed data:");