Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. const createDataSets = (data, features, categoricalFeatures, testSize) => {
  2. const X = data.map(r =>
  3. features.flatMap(f => {
  4. if (categoricalFeatures.has(f)) {
  5. return oneHot(!r[f] ? 0 : r[f], VARIABLE_CATEGORY_COUNT[f]);
  6. }
  7. return !r[f] ? 0 : r[f];
  8. })
  9. );
  10.  
  11. const X_t = normalize(tf.tensor2d(X));
  12.  
  13. const y = tf.tensor(data.map(r => (!r.SalePrice ? 0 : r.SalePrice)));
  14.  
  15. const splitIdx = parseInt((1 - testSize) * data.length, 10);
  16.  
  17. const [xTrain, xTest] = tf.split(X_t, [splitIdx, data.length - splitIdx]);
  18. const [yTrain, yTest] = tf.split(y, [splitIdx, data.length - splitIdx]);
  19.  
  20. return [xTrain, xTest, yTrain, yTest];
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement