Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def trainModel(comm, rankId):
trainingResult = None
# Initialize FileDataSource to retrieve the input data from a .csv file
trainDataSource = FileDataSource(
trainDatasetFileNames[rankId],
DataSourceIface.notAllocateNumericTable,
DataSourceIface.doDictionaryFromContext
)
# Create Numeric Tables for training data and labels
trainData = HomogenNumericTable(NUM_FEATURES, 0, NumericTableIface.doNotAllocate)
trainDependentVariables = HomogenNumericTable(NUM_DEPENDENT_VARS, 0, NumericTableIface.doNotAllocate)
mergedData = MergedNumericTable(trainData, trainDependentVariables)
# Retrieve the data from the input file
trainDataSource.loadDataBlock(mergedData)
# Create an algorithm object to train the ridge regression model based on the local-node data
localAlgorithm = training.Distributed(step1Local)
def loadData(fileName):
# Initialize FileDataSource to retrieve the input data from a .csv file
trainDataSource = FileDataSource(
fileName, DataSourceIface.notAllocateNumericTable, DataSourceIface.doDictionaryFromContext
)
# Create Numeric Tables for training data and dependent variables
data = HomogenNumericTable(nFeatures, 0, NumericTableIface.notAllocate)
dependentVar = HomogenNumericTable(1, 0, NumericTableIface.notAllocate)
mergedData = MergedNumericTable(data, dependentVar)
# Retrieve the data from input file
trainDataSource.loadDataBlock(mergedData)
dictionary = data.getDictionary()
for i in range(len(categoricalFeaturesIndices)):
dictionary[categoricalFeaturesIndices[i]].featureType = features.DAAL_CATEGORICAL
return data, dependentVar
def trainModel():
global trainingResult
# Initialize FileDataSource to retrieve the input data from a .csv file
trainDataSource = FileDataSource(
trainDatasetFileName, DataSourceIface.notAllocateNumericTable,
DataSourceIface.doDictionaryFromContext
)
# Create Numeric Tables for training data and labels
trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
mergedData = MergedNumericTable(trainData, trainGroundTruth)
# Retrieve the data from the input file
trainDataSource.loadDataBlock(mergedData)
# Create an algorithm object to train the SVM model
algorithm = training.Batch()
algorithm.parameter.kernel = kernel
def trainModel():
# Initialize FileDataSource to retrieve the input data from a .csv file
trainDataSource = FileDataSource(trainDatasetFileName,
DataSource.notAllocateNumericTable,
DataSource.doDictionaryFromContext)
# Create Numeric Tables for training data and dependent variables
trainData = HomogenNumericTable(nFeatures, 0, NumericTable.doNotAllocate)
trainDependentVariables = HomogenNumericTable(nDependentVariables, 0, NumericTable.doNotAllocate)
mergedData = MergedNumericTable(trainData, trainDependentVariables)
# Retrieve the data from input file
trainDataSource.loadDataBlock(mergedData)
# Create an algorithm object to train the ridge regression model with the normal equations method
algorithm = training.Batch()
# Pass a training data set and dependent values to the algorithm
algorithm.input.set(training.data, trainData)
def trainModel():
global trainingResult
# Initialize FileDataSource to retrieve the input data from a .csv file
trainDataSource = FileDataSource(
trainDatasetFileName, DataSourceIface.notAllocateNumericTable,
DataSourceIface.doDictionaryFromContext
)
# Create Numeric Tables for training data and labels
trainData = HomogenNumericTable(nFeatures, 0, NumericTableIface.doNotAllocate)
trainGroundTruth = HomogenNumericTable(1, 0, NumericTableIface.doNotAllocate)
mergedData = MergedNumericTable(trainData, trainGroundTruth)
# Retrieve the data from the input file
trainDataSource.loadDataBlock(mergedData)
# Create an algorithm object to train the multi-class SVM model
algorithm = multi_class_classifier.training.Batch(nClasses,fptype=np.float64)
algorithm.parameter.training = training
def testModel(trainingResult):
# Initialize FileDataSource to retrieve the input data from a .csv file
testDataSource = FileDataSource(testDatasetFileName,
DataSource.doAllocateNumericTable,
DataSource.doDictionaryFromContext)
# Create Numeric Tables for testing data and ground truth values
testData = HomogenNumericTable(nFeatures, 0, NumericTable.doNotAllocate)
testGroundTruth = HomogenNumericTable(nDependentVariables, 0, NumericTable.doNotAllocate)
mergedData = MergedNumericTable(testData, testGroundTruth)
# Load the data from the data file
testDataSource.loadDataBlock(mergedData)
# Create an algorithm object to predict values of ridge regression
algorithm = prediction.Batch()
# Pass a testing data set and the trained model to the algorithm
algorithm.input.setTable(prediction.data, testData)
import daal.algorithms.normalization.minmax as minmax
from daal.data_management import DataSourceIface, FileDataSource
utils_folder = os.path.realpath(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
if utils_folder not in sys.path:
sys.path.insert(0, utils_folder)
from utils import printNumericTable
# Input data set parameters
datasetName = os.path.join('..', 'data', 'batch', 'normalization.csv')
if __name__ == "__main__":
# Retrieve the input data
dataSource = FileDataSource(datasetName,
DataSourceIface.doAllocateNumericTable,
DataSourceIface.doDictionaryFromContext)
dataSource.loadDataBlock()
data = dataSource.getNumericTable()
# Create an algorithm
algorithm = minmax.Batch(method=minmax.defaultDense)
# Set lower and upper bounds for the algorithm
algorithm.parameter.lowerBound = -1.0
algorithm.parameter.upperBound = 1.0
# Set an input object for the algorithm
algorithm.input.set(minmax.data, data)
def trainModel():
global trainingResult
# Initialize FileDataSource to retrieve the input data from a .csv file
trainLabelsDataSource = FileDataSource(
trainLabelsFileName, DataSourceIface.doAllocateNumericTable,
DataSourceIface.doDictionaryFromContext
)
# Create numeric table for training data
trainData = createSparseTable(trainDatasetFileName)
# Retrieve the data from the input file
trainLabelsDataSource.loadDataBlock()
# Create an algorithm object to train the multi-class SVM model
algorithm = multi_class_classifier.training.Batch(nClasses)
algorithm.parameter.training = trainingAlg
algorithm.parameter.prediction = predictionAlg