47 import daal.algorithms.kmeans
as kmeans
48 import daal.algorithms.kmeans.init
as init
49 from daal.data_management
import FileDataSource, DataSourceIface
50 from daal.services
import Environment
53 datasetFileName = os.path.join(
'..',
'data',
'batch',
'kmeans_dense.csv')
62 if __name__ ==
"__main__":
65 nThreadsInit = Environment.getInstance().getNumberOfThreads()
68 Environment.getInstance().setNumberOfThreads(nThreads)
71 nThreadsNew = Environment.getInstance().getNumberOfThreads()
74 dataSource = FileDataSource(
75 datasetFileName, DataSourceIface.doAllocateNumericTable,
76 DataSourceIface.doDictionaryFromContext
80 dataSource.loadDataBlock()
83 initAlg = init.Batch(nClusters)
85 initAlg.input.set(init.data, dataSource.getNumericTable())
86 res = initAlg.compute()
87 centroids = res.get(init.centroids)
90 algorithm = kmeans.Batch(nClusters, nIterations)
92 algorithm.input.set(kmeans.data, dataSource.getNumericTable())
93 algorithm.input.set(kmeans.inputCentroids, centroids)
96 unused_result = algorithm.compute()
98 print(
"Initial number of threads: {}".format(nThreadsInit))
99 print(
"Number of threads to set: {}".format(nThreads))
100 print(
"Number of threads after setting: {}".format(nThreadsNew))