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 from daal.algorithms
import classifier
23 from daal.algorithms.stump
import training, prediction
24 from daal.data_management
import (
25 FileDataSource, DataSourceIface, HomogenNumericTable, MergedNumericTable, NumericTableIface
28 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
29 if utils_folder
not in sys.path:
30 sys.path.insert(0, utils_folder)
31 from utils
import printNumericTables
33 DAAL_PREFIX = os.path.join(
'..',
'data')
37 trainDatasetFileName = os.path.join(DAAL_PREFIX,
'batch',
'stump_train.csv')
38 testDatasetFileName = os.path.join(DAAL_PREFIX,
'batch',
'stump_test.csv')
41 predictionResult =
None
42 testGroundTruth =
None
48 trainDataSource = FileDataSource(
50 DataSourceIface.notAllocateNumericTable,
51 DataSourceIface.doDictionaryFromContext
55 trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
56 trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
57 mergedData = MergedNumericTable(trainData, trainGroundTruth)
60 trainDataSource.loadDataBlock(mergedData)
63 algorithm = training.Batch()
66 algorithm.input.set(classifier.training.data, trainData)
67 algorithm.input.set(classifier.training.labels, trainGroundTruth)
70 trainingResult = algorithm.compute()
74 global predictionResult, testGroundTruth
77 testDataSource = FileDataSource(
79 DataSourceIface.notAllocateNumericTable,
80 DataSourceIface.doDictionaryFromContext
84 testData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
85 testGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
86 mergedData = MergedNumericTable(testData, testGroundTruth)
89 testDataSource.loadDataBlock(mergedData)
92 algorithm = prediction.Batch()
95 algorithm.input.setTable(classifier.prediction.data, testData)
96 algorithm.input.setModel(classifier.prediction.model,
97 trainingResult.get(classifier.training.model))
100 predictionResult = algorithm.compute()
106 predictionResult.get(classifier.prediction.prediction),
107 "Ground truth",
"Classification results",
108 "Stump classification results (first 20 observations):", 20, flt64=
False)
110 if __name__ ==
"__main__":