node.jsregressionbrain.js

Can Brain.js do a regression?


I'm trying to define a price for websites using some attributes like numbers of visists, categories, age ... But the things is lineare regression is not accurate enought, so I would like to know if brain js can be train to do some sort of regression ?

I have a list of websites with all attributes and their price to train the NN and in my end just by sending the attributes I want the NN to return me the price


Solution

  • I sorted out your regression possibility in `brain.js` through a `github` issue.

    All you have to do is to represent each of your input and output between a range of [0-1]


    First combination would be of age i-e from 0 to 1

    let 0.10 means 10 years old and remember that age cannot exceed more than 1.0


    Second combination would be of visits per hours/day/week from 0 to 1

    let 0.25 means 25 visits per hour or you can represent 0.25 based on your own need of visits per hour/day/week etc.


    Third combination would be of different category, each having different value from 0 to 1

    let 0.01 represents first category for example sports.


    Fourth combination would be of output i-e price each having different value from 0 to 1

    let 0.30 represents price equal to 30 dollar.


    Code

    const brain = require('brain.js');
    
    const network = new brain.NeuralNetwork();
    
    network.train([
            // [age, visits, category]     [price]
            
      { input: [0.10, 0.20, 0.40], output: [0.30] }, // 1 input
      { input: [0.10, 0.50, 0.50], output: [0.60] }, // 2 input
      { input: [0.10, 0.40, 0.60], output: [0.20] }, // 3 input
      { input: [0.10, 0.40, 0.50], output: [0.50] }, // 4 input
      { input: [0.10, 0.30, 0.30], output: [0.90] }, // 5 input
      { input: [0.10, 0.70, 0.30], output: [0.70] }  // 6 input
    ]);
    
    
    //multiply answer by 100 to get price value 
    const output = network.run([0.10, 0.50, 0.60])*100;
    
    console.log(`Price: ${output}`); // output lies between 2 and 3 input         
                                                              i-e 38.1325