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.
32 import daal.algorithms.optimization_solver
as optimization_solver
33 import daal.algorithms.optimization_solver.logistic_loss
34 import daal.algorithms.optimization_solver.sgd
35 import daal.algorithms.optimization_solver.iterative_solver
37 from daal.data_management
import (
38 DataSourceIface, FileDataSource, HomogenNumericTable, MergedNumericTable, NumericTableIface
41 utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
42 if utils_folder
not in sys.path:
43 sys.path.insert(0, utils_folder)
44 from utils
import printNumericTable
46 datasetFileName = os.path.join(
'..',
'data',
'batch',
'custom.csv')
51 accuracyThreshold = 0.02
53 initialPoint = np.array([[1], [1], [1], [1], [1]], dtype=np.float64)
55 if __name__ ==
"__main__":
58 dataSource = FileDataSource(datasetFileName,
59 DataSourceIface.notAllocateNumericTable,
60 DataSourceIface.doDictionaryFromContext)
63 data = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
64 dependentVariables = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
65 mergedData = MergedNumericTable(data, dependentVariables)
68 dataSource.loadDataBlock(mergedData)
70 nVectors = data.getNumberOfRows()
72 logistic_lossObjectiveFunction = optimization_solver.logistic_loss.Batch(nVectors)
73 logistic_lossObjectiveFunction.input.set(optimization_solver.logistic_loss.data, data)
74 logistic_lossObjectiveFunction.input.set(optimization_solver.logistic_loss.dependentVariables, dependentVariables)
77 sgdAlgorithm = optimization_solver.sgd.Batch(logistic_lossObjectiveFunction)
80 sgdAlgorithm.input.setInput(optimization_solver.iterative_solver.inputArgument, HomogenNumericTable(initialPoint))
81 sgdAlgorithm.parameter.learningRateSequence = HomogenNumericTable(1, 1, NumericTableIface.doAllocate, learningRate)
82 sgdAlgorithm.parameter.nIterations = nIterations
83 sgdAlgorithm.parameter.accuracyThreshold = accuracyThreshold
87 res = sgdAlgorithm.compute()
90 printNumericTable(res.getResult(optimization_solver.iterative_solver.minimum),
"Minimum:")
91 printNumericTable(res.getResult(optimization_solver.iterative_solver.nIterations),
"Number of iterations performed:")