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',
'logreg_train.csv')
39 testDatasetFileName = os.path.join(DAAL_PREFIX,
'batch',
'logreg_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)
73 algorithm.parameter().penaltyL1=0.1;
74 algorithm.parameter().penaltyL2=0.1;
77 trainingResult = algorithm.compute()
78 model = trainingResult.get(classifier.training.model)
79 printNumericTable(model.getBeta(),
"Logistic Regression coefficients:")
82 global testGroundTruth, predictionResult
85 testDataSource = FileDataSource(
87 DataSourceIface.notAllocateNumericTable,
88 DataSourceIface.doDictionaryFromContext
92 testData = HomogenNumericTable(nFeatures, 0, NumericTableIface.notAllocate)
93 testGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.notAllocate)
94 mergedData = MergedNumericTable(testData, testGroundTruth)
97 testDataSource.loadDataBlock(mergedData)
100 algorithm = prediction.Batch(nClasses)
103 algorithm.input.setTable(classifier.prediction.data, testData)
104 algorithm.input.setModel(classifier.prediction.model, model)
105 algorithm.parameter().resultsToCompute |= logistic_regression.prediction.computeClassesProbabilities | logistic_regression.prediction.computeClassesLogProbabilities
109 predictionResult = algorithm.compute()
114 printNumericTable(predictionResult.get(classifier.prediction.prediction),
"Logistic regression prediction results (first 10 rows):",10)
115 printNumericTable(testGroundTruth,
"Ground truth (first 10 rows):",10)
116 printNumericTable(predictionResult.get(logistic_regression.prediction.probabilities),
"Logistic regression prediction probabilities (first 10 rows):",10)
117 printNumericTable(predictionResult.get(logistic_regression.prediction.logProbabilities),
"Logistic regression prediction log probabilities (first 10 rows):",10)
119 if __name__ ==
"__main__":