I am complete beginner to AI as well as tensorflow.js. Currently following the Machine Learning course of Stephen Grider. I should have got a output after the following code but instead i got error. Please help:
code:
linear-regression.js:
const tf = require('@tensorflow/tfjs');
class LinearRegression {
constructor(features, labels, options) {
this.features = tf.tensor(features);
this.labels = tf.tensor(labels);
this.features = tf.ones([this.features.shape[0], 1]).concat(this.features) //generates the column of one for the horse power
this.options = Object.assign(
{ learningRate: 0.1, iterations: 1000 },
options
); //default value is 0.1, if the learning rate is provided, the value is overrided... iteration no. of times gradient decent runs
this.weights = tf.zeros([2, 1]); // intial tensor of both m and b are zeros
}
gradientDescent() {
const currentGuesses = this.features.matMul(this.weights); //matMul is matrix multiplication which is features * weights
const differences = currentGuesses.sub(this.labels); //(features * weights) - labels
const slopes = this.features
.transpose()
.matMul(differences)
.div(features.shape[0]); // slope of MSE with respect to both m and b. features * ((features * weights) - labels) / total no. of features.
this.weights = this.weights.sub(slopes.mul(this.options.learningRate));
}
train() {
for (let i=0; i < this.options.iterations; i++) {
this.gradientDescent();
}
/*test(testFeatures, testLabels) {
testFeatures = tf.tensor(testFeatures);
testLabels = tf.tensor(testLabels);
} */
}
}
module.exports = LinearRegression;
index.js:
require('@tensorflow/tfjs-node');
const tf = require('@tensorflow/tfjs');
const loadCSV = require('./load-csv');
const LinearRegression = require('./linear-regression');
let { features, labels, testFeatures, testLabels } =loadCSV('./cars.csv', {
shuffle: true,
splitTest: 50,
dataColumns: ['horsepower'],
labelColumns: ['mpg']
});
const regression = new LinearRegression(features, labels, {
learningRate: 0.002,
iterations: 100
});
regression.train();
console.log(
'Updated M is:',
regression.weights.get(1, 0),
'Updated B is:',
regression.weights.get(0, 0)
);
Error:
D:\Application Development\MLKits-master\MLKits-master\regressions\node_modules\@tensorflow\tfjs-core\dist\ops\operation.js:32
throw ex;
^
Error: Error in matMul: inner shapes (1) and (2) of Tensors with shapes 684,1 and 2,1 and transposeA=false and transposeB=false must match.
at Object.assert (D:\Application Development\MLKits-master\MLKits-master\regressions\node_modules\@tensorflow\tfjs-core\dist\util.js:36:15)
at matMul_ (D:\Application Development\MLKits-master\MLKits-master\regressions\node_modules\@tensorflow\tfjs-core\dist\ops\matmul.js:25:10)
at Object.matMul (D:\Application Development\MLKits-master\MLKits-master\regressions\node_modules\@tensorflow\tfjs-core\dist\ops\operation.js:23:29)
at Tensor.matMul (D:\Application Development\MLKits-master\MLKits-master\regressions\node_modules\@tensorflow\tfjs-core\dist\tensor.js:315:26)
at LinearRegression.gradientDescent (D:\Application Development\MLKits-master\MLKits-master\regressions\linear-regression.js:19:46)
at LinearRegression.train (D:\Application Development\MLKits-master\MLKits-master\regressions\linear-regression.js:34:18)
at Object.<anonymous> (D:\Application Development\MLKits-master\MLKits-master\regressions\index.js:18:12)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
stromectol pill for humans – ivermectin 3mg tablets ivermectin 0.2mg
lyrica capsules 25 mg – online pharmacy canada best canadian online pharmacy reviews
no rx viagra – best female viagra brand female viagra pharmacy
furosemide 120 mg daily – can i buy lasix over the counter in australia furosemide 40 mg tablets online
clomid tablets – clomid warnings clomid online no prescription
sildenafil cream in i – canadian pharmacy viagra 150 mg sildenafil daily use
can you buy cialis in canada over the counter – cialis original buy cialis 5mg online
casino online gambling – realslotsgam real money casino games
home remedies for ed erectile dysfunction – treatment of ed best natural ed pills
generic prednisone 5mg online – cost of 2.5mg prednisone prednisone 10 mg purchase
viagra San Antonio – sildenafil otc india viagra 100 mg tablets
generic cialis soft tabs suppliers – Cialis low price cheap cialis canadian
buy ivermectin for humans uk – stromectol buy ivermectin 5 mg price
causes of ed – ed drugs compared ed drugs list
buy ventolin – site generic ventolin price
ivermectina 6mg – purchase stromectol how to buy stromectol
fda ivermectin – price of ivermectin ivermectin tablets uk
oral ivermectin cost – stromcv buy liquid ivermectin
essay buy online – help with research paper buy cheap essays online
prednisone price – prednisone 60mg without prescription 200mg prednisone
buy plaquenil without prescription – cenforce 50mg pill buy valacyclovir 500mg online cheap
sildalis us – brand sildalis metformin cost
hydroxychloroquine 400mg usa – brand plaquenil 200mg order plaquenil 200mg generic
sildenafil 50 mg – order cialis 20mg online cheap female cialis pill
cheap generic cialis for sale where to buy tadalafil on line
pregabalin order – clomid online buy purchase azithromycin pill
tadalafil blood pressure cialis without prescription
tadalafil liquid cost of cialis
purchase hydroxychloroquine pills – order chloroquine 250mg sale buy chloroquine pills
best price usa tadalafil tadalafil side effects
where to get tadalafil tadalafil order online no prescription
buy tadalafil tadalafil without a doctor prescription
600227 278165Hello! I simply want to make a enormous thumbs up with the fantastic information youve here during this post. We are returning to your blog for additional soon. 761230
cialis without a prescription where to buy cialis without prescription
buy generic cialis online with mastercard tadalafil generic
side effects for tadalafil tadalafil online with out prescription
tadalafil cost in canada where to get tadalafil
what is tadalafil tadalafil
brand provigil 100mg provigil drug
ivermectin for covid
ivermectin 6 mg tablet buy stromectol canada buy stromectol