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 DataSourceIface, FileDataSource
26 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
27 if utils_folder
not in sys.path:
28 sys.path.insert(0, utils_folder)
29 from utils
import printNumericTables, createSparseTable
32 DATA_PREFIX = os.path.join(
'..',
'data',
'batch')
34 trainDatasetFileName = os.path.join(DATA_PREFIX,
'svm_two_class_train_csr.csv')
35 trainLabelsFileName = os.path.join(DATA_PREFIX,
'svm_two_class_train_labels.csv')
36 testDatasetFileName = os.path.join(DATA_PREFIX,
'svm_two_class_test_csr.csv')
37 testLabelsFileName = os.path.join(DATA_PREFIX,
'svm_two_class_test_labels.csv')
40 kernel = kernel_function.linear.Batch(method=kernel_function.linear.fastCSR)
44 predictionResult =
None
51 trainLabelsDataSource = FileDataSource(
52 trainLabelsFileName, DataSourceIface.doAllocateNumericTable,
53 DataSourceIface.doDictionaryFromContext
57 trainData = createSparseTable(trainDatasetFileName)
60 trainLabelsDataSource.loadDataBlock()
63 algorithm = training.Batch()
65 algorithm.parameter.kernel = kernel
66 algorithm.parameter.cacheSize = 40000000
69 algorithm.input.set(classifier.training.data, trainData)
70 algorithm.input.set(classifier.training.labels, trainLabelsDataSource.getNumericTable())
73 trainingResult = algorithm.compute()
77 global predictionResult
80 testData = createSparseTable(testDatasetFileName)
83 algorithm = prediction.Batch()
85 algorithm.parameter.kernel = kernel
88 algorithm.input.setTable(classifier.prediction.data, testData)
90 algorithm.input.setModel(classifier.prediction.model, trainingResult.get(classifier.training.model))
96 predictionResult = algorithm.getResult()
102 testLabelsDataSource = FileDataSource(
103 testLabelsFileName, DataSourceIface.doAllocateNumericTable,
104 DataSourceIface.doDictionaryFromContext
107 testLabelsDataSource.loadDataBlock()
108 testGroundTruth = testLabelsDataSource.getNumericTable()
111 testGroundTruth, predictionResult.get(classifier.prediction.prediction),
112 "Ground truth\t",
"Classification results",
113 "SVM classification results (first 20 observations):", 20, flt64=
False
116 if __name__ ==
"__main__":