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 kernel_function, classifier
24 from daal.data_management
import (
25 DataSourceIface, FileDataSource, 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
34 DATA_PREFIX = os.path.join(
'..',
'data',
'batch')
36 trainDatasetFileName = os.path.join(DATA_PREFIX,
'svm_two_class_train_dense.csv')
37 testDatasetFileName = os.path.join(DATA_PREFIX,
'svm_two_class_test_dense.csv')
42 kernel = kernel_function.linear.Batch()
46 predictionResult =
None
47 testGroundTruth =
None
54 trainDataSource = FileDataSource(
55 trainDatasetFileName, DataSourceIface.notAllocateNumericTable,
56 DataSourceIface.doDictionaryFromContext
60 trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
61 trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
62 mergedData = MergedNumericTable(trainData, trainGroundTruth)
65 trainDataSource.loadDataBlock(mergedData)
68 algorithm = training.Batch()
70 algorithm.parameter.kernel = kernel
71 algorithm.parameter.cacheSize = 600000000
74 algorithm.input.set(classifier.training.data, trainData)
75 algorithm.input.set(classifier.training.labels, trainGroundTruth)
78 trainingResult = algorithm.compute()
82 global predictionResult, testGroundTruth
85 testDataSource = FileDataSource(
86 testDatasetFileName, DataSourceIface.notAllocateNumericTable,
87 DataSourceIface.doDictionaryFromContext
91 testData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
92 testGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
93 mergedData = MergedNumericTable(testData, testGroundTruth)
96 testDataSource.loadDataBlock(mergedData)
99 algorithm = prediction.Batch()
101 algorithm.parameter.kernel = kernel
104 algorithm.input.setTable(classifier.prediction.data, testData)
105 algorithm.input.setModel(classifier.prediction.model, trainingResult.get(classifier.training.model))
111 predictionResult = algorithm.getResult()
117 testGroundTruth, predictionResult.get(classifier.prediction.prediction),
118 "Ground truth\t",
"Classification results",
119 "SVM classification results (first 20 observations):", 20, flt64=
False
122 if __name__ ==
"__main__":