* Load a local csv file and prepare the data for training. Data source: * https://archive.ics.uci.edu/ml/datasets/Abalone * * @param {string} csvPath The path to csv file. * @returns {tf.data.Dataset} The loaded and prepared Dataset.
(csvPath)
| 25 | * @returns {tf.data.Dataset} The loaded and prepared Dataset. |
| 26 | */ |
| 27 | async function createDataset(csvPath) { |
| 28 | const dataset = tf.data.csv( |
| 29 | csvPath, {hasHeader: true, columnConfigs: {'rings': {isLabel: true}}}); |
| 30 | const numOfColumns = (await dataset.columnNames()).length - 1; |
| 31 | // Convert features and labels. |
| 32 | return { |
| 33 | dataset: dataset.map(row => { |
| 34 | const rawFeatures = row['xs']; |
| 35 | const rawLabel = row['ys']; |
| 36 | const convertedFeatures = Object.keys(rawFeatures).map(key => { |
| 37 | switch (rawFeatures[key]) { |
| 38 | case 'F': |
| 39 | return 0; |
| 40 | case 'M': |
| 41 | return 1; |
| 42 | case 'I': |
| 43 | return 2; |
| 44 | default: |
| 45 | return Number(rawFeatures[key]); |
| 46 | } |
| 47 | }); |
| 48 | const convertedLabel = [rawLabel['rings']]; |
| 49 | return {xs: convertedFeatures, ys: convertedLabel}; |
| 50 | }), |
| 51 | numOfColumns: numOfColumns |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | module.exports = createDataset; |
no outgoing calls
no test coverage detected