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.
22 import daal.algorithms.kmeans.init
23 from daal.algorithms
import kmeans
24 from daal.data_management
import FileDataSource, DataSourceIface
26 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
27 if utils_folder
not in sys.path:
28 sys.path.insert(0, utils_folder)
29 from utils
import printNumericTable
31 DAAL_PREFIX = os.path.join(
'..',
'data')
34 datasetFileName = os.path.join(DAAL_PREFIX,
'batch',
'kmeans_dense.csv')
39 if __name__ ==
"__main__":
42 dataSource = FileDataSource(
44 DataSourceIface.doAllocateNumericTable,
45 DataSourceIface.doDictionaryFromContext
49 dataSource.loadDataBlock()
52 initAlg = kmeans.init.Batch(nClusters, method=kmeans.init.randomDense)
54 initAlg.input.set(kmeans.init.data, dataSource.getNumericTable())
56 res = initAlg.compute()
57 centroidsResult = res.get(kmeans.init.centroids)
60 algorithm = kmeans.Batch(nClusters, 0, method=kmeans.lloydDense)
62 algorithm.input.set(kmeans.data, dataSource.getNumericTable())
63 algorithm.input.set(kmeans.inputCentroids, centroidsResult)
65 res = algorithm.compute()
68 printNumericTable(res.get(kmeans.assignments),
"First 10 cluster assignments:", 10)