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.
21 import daal.algorithms.kmeans
as kmeans
22 import daal.algorithms.kmeans.init
as init
23 from daal.data_management
import FileDataSource, DataSourceIface
24 from daal.services
import Environment
27 datasetFileName = os.path.join(
'..',
'data',
'batch',
'kmeans_dense.csv')
36 if __name__ ==
"__main__":
39 nThreadsInit = Environment.getInstance().getNumberOfThreads()
42 Environment.getInstance().setNumberOfThreads(nThreads)
45 nThreadsNew = Environment.getInstance().getNumberOfThreads()
48 dataSource = FileDataSource(
49 datasetFileName, DataSourceIface.doAllocateNumericTable,
50 DataSourceIface.doDictionaryFromContext
54 dataSource.loadDataBlock()
57 initAlg = init.Batch(nClusters)
59 initAlg.input.set(init.data, dataSource.getNumericTable())
60 res = initAlg.compute()
61 centroids = res.get(init.centroids)
64 algorithm = kmeans.Batch(nClusters, nIterations)
66 algorithm.input.set(kmeans.data, dataSource.getNumericTable())
67 algorithm.input.set(kmeans.inputCentroids, centroids)
70 unused_result = algorithm.compute()
72 print(
"Initial number of threads: {}".format(nThreadsInit))
73 print(
"Number of threads to set: {}".format(nThreads))
74 print(
"Number of threads after setting: {}".format(nThreadsNew))