title: combining one hot encoded category data and continuous data examples in TensorFlow JS
body: <p>When using both one-hot encoded category data and numerically variable data how do you combine these different types of data to fit the model?</p>
  
  <p>Previously using <strong>TensorflowJS</strong>, and this is just my side project that I am using to learn more about google's tf, I have used only one-hot encoded data for both the feature and label values. All the features were the same shape as were the labels. I am simply building a prediction model for features that are one-hot encoded names such as</p>
  
  <pre><code>"name1" = [1,0,0]
  "name2" = [0,1,0]
  ...
  </code></pre>
  
  <p>with outcomes that are one-hot encoded too such as </p>
  
  <pre><code>"outcome1" = [1,0,0]
  "outcome2" = [0,1,0]
  ...
  </code></pre>
  
  <p>This worked pretty well and I was able to build a lovely model that when tested worked quite well.</p>
  
  <p>However once I wanted to do some feature engineering and use a numerically continuous piece of data I could not see how to combine the category and continuous data.</p>
  
  <p>What I am wanting to do is use an additional non category piece of variable data. So my features would be</p>
  
  <pre><code>"name1" = [1,0,0]
  "name2" = [0,1,0]
  variablePieceOfInformation = 10
  </code></pre>
  
  <p>I do not initially see a way within tensor flow of using these pieces of data together.</p>
  
  <p>Initially all my features were identically sized one hot encoded category names and my labels were one hot encoded outcomes that I wanted to predict. </p>
  
  <p>Now I want to use an additional piece of information that is continuously variable and I do not see examples on how to combine the two types. </p>
  
  <p>What I was expecting was that there may be a way of combining category (onehot encoded) and continuously variable data.</p>
  
  <p><a href="https://github.com/ghinks/epl-ml-mono-repo/blob/master/packages/epl-base-model/src/index.ts" rel="nofollow noreferrer">my git repo</a></p>
  
  <pre><code>import getTrainingData, { TrainingData, getNames } from "./getModelData";
  import save from "./saveModel";
  import { numAllTimeTeams } from "@gvhinks/epl-constants";
  
  const createModel = async (): Promise&lt;tf.Sequential&gt; =&gt; {
    const model: tf.Sequential = tf.sequential({
      name: "predict"
    });
    model.add(tf.layers.dense({inputShape: [2,numAllTimeTeams], units: 3, useBias: true, name:"teams_layer"}));
    model.add(tf.layers.flatten());
    model.add(tf.layers.dense({units: 3, useBias: true, name: "results_layer"}));
    model.compile({optimizer: tf.train.adam(0.001), loss: 'meanSquaredError'});
    const { labelValues, featureValues } = await getTrainingData();
    const numTeamsInLeague: number = (featureValues[0][0]).length;
    const featureTensors = tf.tensor3d(featureValues, [featureValues.length, 2, numTeamsInLeague], 'int32');
    const labelTensors = tf.tensor2d(labelValues, [labelValues.length, 3], 'int32');
    const fitArgs = {
      batchSize: 500,
      epochs: 200,
      verbose: 0
    };
    await model.fit(featureTensors, labelTensors, fitArgs);
    return model;
  };
  
  export { getTrainingData, createModel as default, TrainingData, getNames, save };```
  </code></pre>