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 logistic_regression
23 from daal.algorithms.logistic_regression
import prediction, training
24 from daal.algorithms
import classifier
25 from daal.data_management
import (
26 FileDataSource, DataSourceIface, NumericTableIface, HomogenNumericTable,
27 MergedNumericTable, features
30 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
31 if utils_folder
not in sys.path:
32 sys.path.insert(0, utils_folder)
33 from utils
import printNumericTable, printNumericTables
35 DAAL_PREFIX = os.path.join(
'..',
'data')
38 trainDatasetFileName = os.path.join(DAAL_PREFIX,
'batch',
'binary_cls_train.csv')
39 testDatasetFileName = os.path.join(DAAL_PREFIX,
'batch',
'binary_cls_test.csv')
46 predictionResult =
None
47 testGroundTruth =
None
53 trainDataSource = FileDataSource(
55 DataSourceIface.notAllocateNumericTable,
56 DataSourceIface.doDictionaryFromContext
60 trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.notAllocate)
61 trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.notAllocate)
62 mergedData = MergedNumericTable(trainData, trainGroundTruth)
65 trainDataSource.loadDataBlock(mergedData)
68 algorithm = training.Batch(nClasses)
71 algorithm.input.set(classifier.training.data, trainData)
72 algorithm.input.set(classifier.training.labels, trainGroundTruth)
75 trainingResult = algorithm.compute()
76 model = trainingResult.get(classifier.training.model)
77 printNumericTable(model.getBeta(),
"Logistic Regression coefficients:")
80 global testGroundTruth, predictionResult
83 testDataSource = FileDataSource(
85 DataSourceIface.notAllocateNumericTable,
86 DataSourceIface.doDictionaryFromContext
90 testData = HomogenNumericTable(nFeatures, 0, NumericTableIface.notAllocate)
91 testGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.notAllocate)
92 mergedData = MergedNumericTable(testData, testGroundTruth)
95 testDataSource.loadDataBlock(mergedData)
98 algorithm = prediction.Batch(nClasses)
101 algorithm.input.setTable(classifier.prediction.data, testData)
102 algorithm.input.setModel(classifier.prediction.model, model)
106 predictionResult = algorithm.compute()
111 printNumericTable(predictionResult.get(classifier.prediction.prediction),
"Logistic regression prediction results (first 10 rows):",10)
112 printNumericTable(testGroundTruth,
"Ground truth (first 10 rows):",10)
114 if __name__ ==
"__main__":