I have this code on a node.js playground. I'm experimenting with brain.js and I want to predict the probability that a team will win a match.
NB: I saw this post where the user was trying to do something similar, not sure if the solution was looking something similar to my code
var playground = require("playground")
const brain = require("brain.js")
const network = new brain.NeuralNetwork();
const samples = [
{ homeTeam: "Lazio",
homeTeamId: 1,
awayTeam: "Inter",
awayTeamId: 2,
matchResult: 1
},
{ homeTeam: "Juventus",
homeTeamId: 3,
awayTeam: "Roma",
awayTeamId: 4,
matchResult: 1
},
{ homeTeam: "Napoli",
homeTeamId: 5,
awayTeam: "Sampdoria",
awayTeamId: 6,
matchResult: 0
},
{ homeTeam: "Udinese",
homeTeamId: 7,
awayTeam: "Monza",
awayTeamId: 8,
matchResult: 1
},
{ homeTeam: "Verona",
homeTeamId: 9,
awayTeam: "Milan",
awayTeamId: 10,
matchResult: 0
}
]
// network.train([
// { input: [0, 0, 0], output: [0] },
// { input: [0, 0, 1], output: [0] },
// { input: [0, 1, 1], output: [0] },
// { input: [1, 0, 1], output: [1] },
// { input: [1, 1, 1], output: [1] }
// ]);
network.train( samples.map( (sample, i) => {
return {
input: [sample.homeTeamId, sample.awayTeamId],
output: [sample.matchResult]
}
//{ input: [1, 2], output: [1] }, // Team 2 wins
//{ input: [1, 3], output: [1] }, // Team 3 wins
//{ input: [2, 3], output: [0] }, // Team 2 wins
//{ input: [2, 4], output: [1] }, // Team 4 wins
//{ input: [1, 2], output: [0] }, // Team 1 wins
//{ input: [1, 3], output: [0] }, // Team 1 wins
//{ input: [3, 4], output: [0] } // Team 3 wins
}));
const output = network.run([2, 3]);
console.log(`Prob: ${output}`);
My idea is to pass the results of each single match played in the last two soccer season to train the network.
I want to give to each football team a static id that so I can call the network.run([3,1]) to get a prediction of the next match where the team with the id 3 will play against team with id 1.
At the moment the code seems not working at all, I will always get a prediction of "Prob: 0.9995707273483276" in the console log, also if I pass different teams id eg. network.run([2,4]), network.run([5,7])
How I can corretcly make a prediction?Maybe I'm using the wrong method or miss something?
Will be this possible also with tensorflow.js eventually?
WE are together. Use this to get some ideas https://github.com/lukewduncan/brain-js-predictor/blob/master/routes/index.js
and