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 decision_forest
23 from daal.algorithms.decision_forest.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.nTrees = nTrees
78 algorithm.parameter.varImportance = decision_forest.training.MDA_Raw
79 algorithm.parameter.resultsToCompute = decision_forest.training.computeOutOfBagError|decision_forest.training.computeOutOfBagErrorPerObservation;
82 algorithm.input.set(training.data, trainData)
83 algorithm.input.set(training.dependentVariable, trainGroundTruth)
86 trainingResult = algorithm.compute()
87 model = trainingResult.get(training.model)
88 printNumericTable(trainingResult.getTable(training.variableImportance),
"Variable importance results: ")
89 printNumericTable(trainingResult.getTable(training.outOfBagError),
"OOB error: ")
90 printNumericTable(trainingResult.getTable(training.outOfBagError),
"OOB error (first 10 rows): ", 10)
93 global testGroundTruth, predictionResult
96 testDataSource = FileDataSource(
98 DataSourceIface.notAllocateNumericTable,
99 DataSourceIface.doDictionaryFromContext
103 testData = HomogenNumericTable(nFeatures, 0, NumericTableIface.notAllocate)
104 testGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.notAllocate)
105 mergedData = MergedNumericTable(testData, testGroundTruth)
108 testDataSource.loadDataBlock(mergedData)
111 dict = testData.getDictionary()
114 dict[3].featureType = features.DAAL_CATEGORICAL
117 algorithm = prediction.Batch()
120 algorithm.input.setTable(prediction.data, testData)
121 algorithm.input.set(prediction.model, model)
124 predictionResult = algorithm.compute()
130 predictionResult.get(prediction.prediction),
131 "Decision forest prediction results (first 10 rows):", 10
135 "Ground truth (first 10 rows):", 10
138 if __name__ ==
"__main__":