Tensorflow JavaScript error when trying to build LinearregressionWhen to use double or single quotes in JavaScript?How to execute a JavaScript function when I have its name as a stringHow to find event listeners on a DOM node when debugging or from the JavaScript code?Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for it“Cross origin requests are only supported for HTTP.” error when loading a local fileError when trying to build tensorflowGetting “PermissionDeniedError” when running the example program on TensorflowGetting TypeError while training a classifier for iris flower datasetTensorflow model does not minimize errorImplementing LinearRegression model in tensorflow

Non-Jewish family in an Orthodox Jewish Wedding

Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?

N.B. ligature in Latex

How to make payment on the internet without leaving a money trail?

whey we use polarized capacitor?

Can you lasso down a wizard who is using the Levitate spell?

DOS, create pipe for stdin/stdout of command.com(or 4dos.com) in C or Batch?

Can Medicine checks be used, with decent rolls, to completely mitigate the risk of death from ongoing damage?

If Manufacturer spice model and Datasheet give different values which should I use?

Why was the small council so happy for Tyrion to become the Master of Coin?

What defenses are there against being summoned by the Gate spell?

Schwarzchild Radius of the Universe

Example of a relative pronoun

Copenhagen passport control - US citizen

What is the meaning of "of trouble" in the following sentence?

Why is this code 6.5x slower with optimizations enabled?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Can a German sentence have two subjects?

Is there a minimum number of transactions in a block?

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?

"which" command doesn't work / path of Safari?

What Brexit solution does the DUP want?

What do you call a Matrix-like slowdown and camera movement effect?

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?



Tensorflow JavaScript error when trying to build Linearregression


When to use double or single quotes in JavaScript?How to execute a JavaScript function when I have its name as a stringHow to find event listeners on a DOM node when debugging or from the JavaScript code?Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for it“Cross origin requests are only supported for HTTP.” error when loading a local fileError when trying to build tensorflowGetting “PermissionDeniedError” when running the example program on TensorflowGetting TypeError while training a classifier for iris flower datasetTensorflow model does not minimize errorImplementing LinearRegression model in tensorflow






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















I got this error while trying to build linear regression function using the JavaScript framework Tensorflow:



C: .regressionsnode_modules@tensorflowtfjs-nodenode_modules@tensorflowtfjs-coredistenvironment.js:147
throw new Error("Unknown feature " + feature + ".");
^
Error: Unknown feature TENSORLIKE_CHECK_SHAPE_CONSISTENCY.


I think that the bug is in this function:



 at LinearRegression.processFeatures (C:.linear-regression.js:72:19)


Here is the line 72 in the "linear-regression" directory:



 features = tf.tensor(features); 


and feature variable is called from at new LinearRegression (C:.regressionslinear-regression.js:17:26)






const tf = require('@tensorflow/tfjs');
const _ = require('lodash');

/**
* Labels = Tensor of label data
* Features = Tensor of feature data
* n = Number of observations
* W (Weights) = M and B in a tensor
* ( ' ) = transpose
*
* Slope of MSE with respect to M and B function
* dMSE / M and B = Features' * ( (Features*W) - Labels) / n
*/

class LinearRegression
constructor(features, labels, options)
this.features = this.processFeatures(features);
this.labels = tf.tensor(labels);

this.options = Object.assign(
learningRate: 0.1, iterations: 1000 ,
options
);

this.W = tf.zeros([this.features.shape[1],1]);



// vectorize solution
gradientDecsent()
const currentGuesses = this.features.matMul(this.W);
const differences = currentGuesses.sub(this.labels)

const slopes = this.features
.transpose()
.matMul(differences)
.div(this.features.shape[0]);

this.W = this.W.sub(slopes.mul(this.options.learningRate)); // W.shape [2 ,1] now




train()
for (let i = 0; i < this.options.iterations; i++)
this.gradientDecsent();



test(testFeatures, testLabels)
testFeatures = this.processFeatures(testFeatures); // this.features.shape [50, 1]
testLabels = tf.tensor(testLabels); // this.labels.shape [50, 1]

const predictions = testFeatures.matMul(this.W); //error: multiplicatiuon NOT ALLOWED = [50,1] * [2, 1]

//@dev: result in (-) negative number = result of if res > tot
const res = testLabels
.sub(predictions)
.pow(2)
.sum()
.get();
const tot = testLabels
.sub(testLabels.mean())
.pow(2)
.sum()
.get();

return 1 - res / tot;


processFeatures(features)
features = tf.tensor(features);

if(this.mean && this.variance)
return features.sub(this.mean).div(this.variance.pow(0.5));

else
features = this.standardize(features);


features = tf.ones([features.shape[0], 1]).concat(features, 1);
return features;


standardize(features)
const mean, variance = tf.moments(features, 0);
this.mean = mean;
this.variance = variance;

return features.sub(this.mean).div(this.variance.pow(0.5));





module.exports = LinearRegression;





I can find the error in the metrics. I am guessing the error is from a multiplication of matrices syntax which is not allowed and the compiler is giving me an error.



How can I fix this error?










share|improve this question






























    -2















    I got this error while trying to build linear regression function using the JavaScript framework Tensorflow:



    C: .regressionsnode_modules@tensorflowtfjs-nodenode_modules@tensorflowtfjs-coredistenvironment.js:147
    throw new Error("Unknown feature " + feature + ".");
    ^
    Error: Unknown feature TENSORLIKE_CHECK_SHAPE_CONSISTENCY.


    I think that the bug is in this function:



     at LinearRegression.processFeatures (C:.linear-regression.js:72:19)


    Here is the line 72 in the "linear-regression" directory:



     features = tf.tensor(features); 


    and feature variable is called from at new LinearRegression (C:.regressionslinear-regression.js:17:26)






    const tf = require('@tensorflow/tfjs');
    const _ = require('lodash');

    /**
    * Labels = Tensor of label data
    * Features = Tensor of feature data
    * n = Number of observations
    * W (Weights) = M and B in a tensor
    * ( ' ) = transpose
    *
    * Slope of MSE with respect to M and B function
    * dMSE / M and B = Features' * ( (Features*W) - Labels) / n
    */

    class LinearRegression
    constructor(features, labels, options)
    this.features = this.processFeatures(features);
    this.labels = tf.tensor(labels);

    this.options = Object.assign(
    learningRate: 0.1, iterations: 1000 ,
    options
    );

    this.W = tf.zeros([this.features.shape[1],1]);



    // vectorize solution
    gradientDecsent()
    const currentGuesses = this.features.matMul(this.W);
    const differences = currentGuesses.sub(this.labels)

    const slopes = this.features
    .transpose()
    .matMul(differences)
    .div(this.features.shape[0]);

    this.W = this.W.sub(slopes.mul(this.options.learningRate)); // W.shape [2 ,1] now




    train()
    for (let i = 0; i < this.options.iterations; i++)
    this.gradientDecsent();



    test(testFeatures, testLabels)
    testFeatures = this.processFeatures(testFeatures); // this.features.shape [50, 1]
    testLabels = tf.tensor(testLabels); // this.labels.shape [50, 1]

    const predictions = testFeatures.matMul(this.W); //error: multiplicatiuon NOT ALLOWED = [50,1] * [2, 1]

    //@dev: result in (-) negative number = result of if res > tot
    const res = testLabels
    .sub(predictions)
    .pow(2)
    .sum()
    .get();
    const tot = testLabels
    .sub(testLabels.mean())
    .pow(2)
    .sum()
    .get();

    return 1 - res / tot;


    processFeatures(features)
    features = tf.tensor(features);

    if(this.mean && this.variance)
    return features.sub(this.mean).div(this.variance.pow(0.5));

    else
    features = this.standardize(features);


    features = tf.ones([features.shape[0], 1]).concat(features, 1);
    return features;


    standardize(features)
    const mean, variance = tf.moments(features, 0);
    this.mean = mean;
    this.variance = variance;

    return features.sub(this.mean).div(this.variance.pow(0.5));





    module.exports = LinearRegression;





    I can find the error in the metrics. I am guessing the error is from a multiplication of matrices syntax which is not allowed and the compiler is giving me an error.



    How can I fix this error?










    share|improve this question


























      -2












      -2








      -2








      I got this error while trying to build linear regression function using the JavaScript framework Tensorflow:



      C: .regressionsnode_modules@tensorflowtfjs-nodenode_modules@tensorflowtfjs-coredistenvironment.js:147
      throw new Error("Unknown feature " + feature + ".");
      ^
      Error: Unknown feature TENSORLIKE_CHECK_SHAPE_CONSISTENCY.


      I think that the bug is in this function:



       at LinearRegression.processFeatures (C:.linear-regression.js:72:19)


      Here is the line 72 in the "linear-regression" directory:



       features = tf.tensor(features); 


      and feature variable is called from at new LinearRegression (C:.regressionslinear-regression.js:17:26)






      const tf = require('@tensorflow/tfjs');
      const _ = require('lodash');

      /**
      * Labels = Tensor of label data
      * Features = Tensor of feature data
      * n = Number of observations
      * W (Weights) = M and B in a tensor
      * ( ' ) = transpose
      *
      * Slope of MSE with respect to M and B function
      * dMSE / M and B = Features' * ( (Features*W) - Labels) / n
      */

      class LinearRegression
      constructor(features, labels, options)
      this.features = this.processFeatures(features);
      this.labels = tf.tensor(labels);

      this.options = Object.assign(
      learningRate: 0.1, iterations: 1000 ,
      options
      );

      this.W = tf.zeros([this.features.shape[1],1]);



      // vectorize solution
      gradientDecsent()
      const currentGuesses = this.features.matMul(this.W);
      const differences = currentGuesses.sub(this.labels)

      const slopes = this.features
      .transpose()
      .matMul(differences)
      .div(this.features.shape[0]);

      this.W = this.W.sub(slopes.mul(this.options.learningRate)); // W.shape [2 ,1] now




      train()
      for (let i = 0; i < this.options.iterations; i++)
      this.gradientDecsent();



      test(testFeatures, testLabels)
      testFeatures = this.processFeatures(testFeatures); // this.features.shape [50, 1]
      testLabels = tf.tensor(testLabels); // this.labels.shape [50, 1]

      const predictions = testFeatures.matMul(this.W); //error: multiplicatiuon NOT ALLOWED = [50,1] * [2, 1]

      //@dev: result in (-) negative number = result of if res > tot
      const res = testLabels
      .sub(predictions)
      .pow(2)
      .sum()
      .get();
      const tot = testLabels
      .sub(testLabels.mean())
      .pow(2)
      .sum()
      .get();

      return 1 - res / tot;


      processFeatures(features)
      features = tf.tensor(features);

      if(this.mean && this.variance)
      return features.sub(this.mean).div(this.variance.pow(0.5));

      else
      features = this.standardize(features);


      features = tf.ones([features.shape[0], 1]).concat(features, 1);
      return features;


      standardize(features)
      const mean, variance = tf.moments(features, 0);
      this.mean = mean;
      this.variance = variance;

      return features.sub(this.mean).div(this.variance.pow(0.5));





      module.exports = LinearRegression;





      I can find the error in the metrics. I am guessing the error is from a multiplication of matrices syntax which is not allowed and the compiler is giving me an error.



      How can I fix this error?










      share|improve this question
















      I got this error while trying to build linear regression function using the JavaScript framework Tensorflow:



      C: .regressionsnode_modules@tensorflowtfjs-nodenode_modules@tensorflowtfjs-coredistenvironment.js:147
      throw new Error("Unknown feature " + feature + ".");
      ^
      Error: Unknown feature TENSORLIKE_CHECK_SHAPE_CONSISTENCY.


      I think that the bug is in this function:



       at LinearRegression.processFeatures (C:.linear-regression.js:72:19)


      Here is the line 72 in the "linear-regression" directory:



       features = tf.tensor(features); 


      and feature variable is called from at new LinearRegression (C:.regressionslinear-regression.js:17:26)






      const tf = require('@tensorflow/tfjs');
      const _ = require('lodash');

      /**
      * Labels = Tensor of label data
      * Features = Tensor of feature data
      * n = Number of observations
      * W (Weights) = M and B in a tensor
      * ( ' ) = transpose
      *
      * Slope of MSE with respect to M and B function
      * dMSE / M and B = Features' * ( (Features*W) - Labels) / n
      */

      class LinearRegression
      constructor(features, labels, options)
      this.features = this.processFeatures(features);
      this.labels = tf.tensor(labels);

      this.options = Object.assign(
      learningRate: 0.1, iterations: 1000 ,
      options
      );

      this.W = tf.zeros([this.features.shape[1],1]);



      // vectorize solution
      gradientDecsent()
      const currentGuesses = this.features.matMul(this.W);
      const differences = currentGuesses.sub(this.labels)

      const slopes = this.features
      .transpose()
      .matMul(differences)
      .div(this.features.shape[0]);

      this.W = this.W.sub(slopes.mul(this.options.learningRate)); // W.shape [2 ,1] now




      train()
      for (let i = 0; i < this.options.iterations; i++)
      this.gradientDecsent();



      test(testFeatures, testLabels)
      testFeatures = this.processFeatures(testFeatures); // this.features.shape [50, 1]
      testLabels = tf.tensor(testLabels); // this.labels.shape [50, 1]

      const predictions = testFeatures.matMul(this.W); //error: multiplicatiuon NOT ALLOWED = [50,1] * [2, 1]

      //@dev: result in (-) negative number = result of if res > tot
      const res = testLabels
      .sub(predictions)
      .pow(2)
      .sum()
      .get();
      const tot = testLabels
      .sub(testLabels.mean())
      .pow(2)
      .sum()
      .get();

      return 1 - res / tot;


      processFeatures(features)
      features = tf.tensor(features);

      if(this.mean && this.variance)
      return features.sub(this.mean).div(this.variance.pow(0.5));

      else
      features = this.standardize(features);


      features = tf.ones([features.shape[0], 1]).concat(features, 1);
      return features;


      standardize(features)
      const mean, variance = tf.moments(features, 0);
      this.mean = mean;
      this.variance = variance;

      return features.sub(this.mean).div(this.variance.pow(0.5));





      module.exports = LinearRegression;





      I can find the error in the metrics. I am guessing the error is from a multiplication of matrices syntax which is not allowed and the compiler is giving me an error.



      How can I fix this error?






      const tf = require('@tensorflow/tfjs');
      const _ = require('lodash');

      /**
      * Labels = Tensor of label data
      * Features = Tensor of feature data
      * n = Number of observations
      * W (Weights) = M and B in a tensor
      * ( ' ) = transpose
      *
      * Slope of MSE with respect to M and B function
      * dMSE / M and B = Features' * ( (Features*W) - Labels) / n
      */

      class LinearRegression
      constructor(features, labels, options)
      this.features = this.processFeatures(features);
      this.labels = tf.tensor(labels);

      this.options = Object.assign(
      learningRate: 0.1, iterations: 1000 ,
      options
      );

      this.W = tf.zeros([this.features.shape[1],1]);



      // vectorize solution
      gradientDecsent()
      const currentGuesses = this.features.matMul(this.W);
      const differences = currentGuesses.sub(this.labels)

      const slopes = this.features
      .transpose()
      .matMul(differences)
      .div(this.features.shape[0]);

      this.W = this.W.sub(slopes.mul(this.options.learningRate)); // W.shape [2 ,1] now




      train()
      for (let i = 0; i < this.options.iterations; i++)
      this.gradientDecsent();



      test(testFeatures, testLabels)
      testFeatures = this.processFeatures(testFeatures); // this.features.shape [50, 1]
      testLabels = tf.tensor(testLabels); // this.labels.shape [50, 1]

      const predictions = testFeatures.matMul(this.W); //error: multiplicatiuon NOT ALLOWED = [50,1] * [2, 1]

      //@dev: result in (-) negative number = result of if res > tot
      const res = testLabels
      .sub(predictions)
      .pow(2)
      .sum()
      .get();
      const tot = testLabels
      .sub(testLabels.mean())
      .pow(2)
      .sum()
      .get();

      return 1 - res / tot;


      processFeatures(features)
      features = tf.tensor(features);

      if(this.mean && this.variance)
      return features.sub(this.mean).div(this.variance.pow(0.5));

      else
      features = this.standardize(features);


      features = tf.ones([features.shape[0], 1]).concat(features, 1);
      return features;


      standardize(features)
      const mean, variance = tf.moments(features, 0);
      this.mean = mean;
      this.variance = variance;

      return features.sub(this.mean).div(this.variance.pow(0.5));





      module.exports = LinearRegression;





      const tf = require('@tensorflow/tfjs');
      const _ = require('lodash');

      /**
      * Labels = Tensor of label data
      * Features = Tensor of feature data
      * n = Number of observations
      * W (Weights) = M and B in a tensor
      * ( ' ) = transpose
      *
      * Slope of MSE with respect to M and B function
      * dMSE / M and B = Features' * ( (Features*W) - Labels) / n
      */

      class LinearRegression
      constructor(features, labels, options)
      this.features = this.processFeatures(features);
      this.labels = tf.tensor(labels);

      this.options = Object.assign(
      learningRate: 0.1, iterations: 1000 ,
      options
      );

      this.W = tf.zeros([this.features.shape[1],1]);



      // vectorize solution
      gradientDecsent()
      const currentGuesses = this.features.matMul(this.W);
      const differences = currentGuesses.sub(this.labels)

      const slopes = this.features
      .transpose()
      .matMul(differences)
      .div(this.features.shape[0]);

      this.W = this.W.sub(slopes.mul(this.options.learningRate)); // W.shape [2 ,1] now




      train()
      for (let i = 0; i < this.options.iterations; i++)
      this.gradientDecsent();



      test(testFeatures, testLabels)
      testFeatures = this.processFeatures(testFeatures); // this.features.shape [50, 1]
      testLabels = tf.tensor(testLabels); // this.labels.shape [50, 1]

      const predictions = testFeatures.matMul(this.W); //error: multiplicatiuon NOT ALLOWED = [50,1] * [2, 1]

      //@dev: result in (-) negative number = result of if res > tot
      const res = testLabels
      .sub(predictions)
      .pow(2)
      .sum()
      .get();
      const tot = testLabels
      .sub(testLabels.mean())
      .pow(2)
      .sum()
      .get();

      return 1 - res / tot;


      processFeatures(features)
      features = tf.tensor(features);

      if(this.mean && this.variance)
      return features.sub(this.mean).div(this.variance.pow(0.5));

      else
      features = this.standardize(features);


      features = tf.ones([features.shape[0], 1]).concat(features, 1);
      return features;


      standardize(features)
      const mean, variance = tf.moments(features, 0);
      this.mean = mean;
      this.variance = variance;

      return features.sub(this.mean).div(this.variance.pow(0.5));





      module.exports = LinearRegression;






      javascript tensorflow machine-learning






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 6:10









      Pikachu the Purple Wizard

      2,06361529




      2,06361529










      asked Mar 8 at 5:52









      miro_murasmiro_muras

      14




      14






















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55057449%2ftensorflow-javascript-error-when-trying-to-build-linearregression%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55057449%2ftensorflow-javascript-error-when-trying-to-build-linearregression%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved