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.svm
import training, prediction
23 from daal.algorithms
import classifier, kernel_function, multi_class_classifier
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')
36 trainDatasetFileName = os.path.join(DAAL_PREFIX,
'batch',
'svm_multi_class_train_dense.csv')
38 testDatasetFileName = os.path.join(DAAL_PREFIX,
'batch',
'svm_multi_class_test_dense.csv')
43 trainingBatch = training.Batch()
44 predictionBatch = prediction.Batch()
47 predictionResult =
None
48 kernelBatch = kernel_function.linear.Batch()
49 testGroundTruth =
None
56 trainDataSource = FileDataSource(
58 DataSourceIface.notAllocateNumericTable,
59 DataSourceIface.doDictionaryFromContext
63 trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
64 trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
65 mergedData = MergedNumericTable(trainData, trainGroundTruth)
68 trainDataSource.loadDataBlock(mergedData)
71 algorithm = multi_class_classifier.training.Batch(nClasses)
73 algorithm.parameter.training = trainingBatch
74 algorithm.parameter.prediction = predictionBatch
77 algorithm.input.set(classifier.training.data, trainData)
78 algorithm.input.set(classifier.training.labels, trainGroundTruth)
82 trainingResult = algorithm.compute()
86 global predictionResult, testGroundTruth
89 testDataSource = FileDataSource(
91 DataSourceIface.doAllocateNumericTable,
92 DataSourceIface.doDictionaryFromContext
96 testData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
97 testGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
98 mergedData = MergedNumericTable(testData, testGroundTruth)
101 testDataSource.loadDataBlock(mergedData)
104 algorithm = multi_class_classifier.prediction.Batch(nClasses)
106 algorithm.parameter.training = trainingBatch
107 algorithm.parameter.prediction = predictionBatch
110 algorithm.input.setTable(classifier.prediction.data, testData)
111 algorithm.input.setModel(classifier.prediction.model,
112 trainingResult.get(classifier.training.model))
116 predictionResult = algorithm.compute()
123 predictionResult.get(classifier.prediction.prediction),
124 "Ground truth",
"Classification results",
125 "Multi-class SVM classification sample program results (first 20 observations):", 20, flt64=
False
128 if __name__ ==
"__main__":
130 trainingBatch.parameter.cacheSize = 100000000
131 trainingBatch.parameter.kernel = kernelBatch
132 predictionBatch.parameter.kernel = kernelBatch