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 gbt
23 from daal.algorithms.gbt.regression
import prediction, training
24 from daal.data_management
import (
25 FileDataSource, DataSourceIface, NumericTableIface,
26 HomogenNumericTable, MergedNumericTable, features
29 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
30 if utils_folder
not in sys.path:
31 sys.path.insert(0, utils_folder)
32 from utils
import printNumericTable
34 DAAL_PREFIX = os.path.join(
'..',
'data')
37 trainDatasetFileName = os.path.join(DAAL_PREFIX,
'batch',
'df_regression_train.csv')
38 testDatasetFileName = os.path.join(DAAL_PREFIX,
'batch',
'df_regression_test.csv')
47 predictionResult =
None
48 testGroundTruth =
None
55 trainDataSource = FileDataSource(
57 DataSourceIface.notAllocateNumericTable,
58 DataSourceIface.doDictionaryFromContext
62 trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.notAllocate)
63 trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.notAllocate)
64 mergedData = MergedNumericTable(trainData, trainGroundTruth)
67 trainDataSource.loadDataBlock(mergedData)
70 dict = trainData.getDictionary()
73 dict[3].featureType = features.DAAL_CATEGORICAL
76 algorithm = training.Batch()
77 algorithm.parameter().maxIterations = maxIterations
80 algorithm.input.set(training.data, trainData)
81 algorithm.input.set(training.dependentVariable, trainGroundTruth)
84 trainingResult = algorithm.compute()
85 model = trainingResult.get(training.model)
88 global testGroundTruth, predictionResult
91 testDataSource = FileDataSource(
93 DataSourceIface.notAllocateNumericTable,
94 DataSourceIface.doDictionaryFromContext
98 testData = HomogenNumericTable(nFeatures, 0, NumericTableIface.notAllocate)
99 testGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.notAllocate)
100 mergedData = MergedNumericTable(testData, testGroundTruth)
103 testDataSource.loadDataBlock(mergedData)
106 dict = testData.getDictionary()
109 dict[3].featureType = features.DAAL_CATEGORICAL
112 algorithm = prediction.Batch()
115 algorithm.input.setTable(prediction.data, testData)
116 algorithm.input.set(prediction.model, model)
119 predictionResult = algorithm.compute()
125 predictionResult.get(prediction.prediction),
126 "Gradient boosted trees prediction results (first 10 rows):", 10
130 "Ground truth (first 10 rows):", 10
133 if __name__ ==
"__main__":