Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const createDataSets = (data, features, categoricalFeatures, testSize) => {
- const X = data.map(r =>
- features.flatMap(f => {
- if (categoricalFeatures.has(f)) {
- return oneHot(!r[f] ? 0 : r[f], VARIABLE_CATEGORY_COUNT[f]);
- }
- return !r[f] ? 0 : r[f];
- })
- );
- const X_t = normalize(tf.tensor2d(X));
- const y = tf.tensor(data.map(r => (!r.SalePrice ? 0 : r.SalePrice)));
- const splitIdx = parseInt((1 - testSize) * data.length, 10);
- const [xTrain, xTest] = tf.split(X_t, [splitIdx, data.length - splitIdx]);
- const [yTrain, yTest] = tf.split(y, [splitIdx, data.length - splitIdx]);
- return [xTrain, xTest, yTrain, yTest];
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement