Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async prepareDataset(url: string) {
// We want to predict the column "medv", which represents a median value of
// a home (in $1000s), so we mark it as a label.
const csvDataset = tfd.csv(url, {columnConfigs: {medv: {isLabel: true}}});
// Reduces the object-type data to an array of numbers.
const convertedDataset =
csvDataset.map((row: Array<{[key: string]: number}>) => {
const [rawFeatures, rawLabel] = row;
const convertedFeatures = Object.values(rawFeatures);
const convertedLabel = [rawLabel['medv']];
return [convertedFeatures, convertedLabel];
});
return {
dataset: convertedDataset.shuffle(100),
numFeatures: (await csvDataset.columnNames()).length - 1
};
}
}