SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top