I am trying to make a predictive algorithm to help with pricing a vehicle based on the history of sales from a dealership. The historical sales are represented in JSON like the following:
"<DOCUMENT_ID>": {
"company_id": "...",
"data": {
"vehicle": {
"v_acv": 37000,
"v_days": 38,
"v_final_acv": 38332,
"v_final_carg_h": 44650,
"v_final_mmr": 39200,
"v_initial_carg_h": 44625,
"v_initial_mmr": 38500,
"v_miles": 11482,
"v_sell_price": 43981,
"v_source": "USED TRADE",
"v_start_price": 43981,
"v_vehicle": "2021 TOYOTA RAV4 TRD OFF ROAD",
}
},
// ...
}
I have formatted this into an array using the following code for Synaptic:
const vehicleTitleMap = new Map()
const sourceMap = new Map()
let dataSet = []
Object.keys(data).forEach((key) => {
let vehicle = data[key].data.vehicle
let title
if (vehicleTitleMap.has(vehicle.v_title)) {
title = vehicleTitleMap.get(vehicle.v_title)
} else {
title = vehicleTitleMap.size
vehicleTitleMap.set(vehicle.v_title, title)
}
let source
if (sourceMap.has(vehicle.v_source)) {
source = sourceMap.get(vehicle.v_source)
} else {
source = sourceMap.size
sourceMap.set(vehicle.v_source, source)
}
dataSet.push({
input: [
parseInt(vehicle.v_acv),
parseInt(vehicle.v_final_acv),
parseInt(vehicle.v_miles),
parseInt(vehicle.v_days),
parseInt(vehicle.v_initial_mmr),
parseInt(vehicle.v_final_mmr),
parseInt(vehicle.v_initial_carg_h),
parseInt(vehicle.v_final_carg_h),
parseInt(vehicle.v_start_price),
title,
source,
parseInt(vehicle.v_sell_price)
],
output: [parseInt(vehicle.v_sell_price)]
})
dataSet = dataSet.filter(doc => {
return doc.input.every(item => !isNaN(item)) && doc.output.every(item => !isNaN(item))
})
})
Then, the actual code for the Synaptic model:
const network = new synaptic.Architect.Perceptron(12, 4, 1)
const trainer = new synaptic.Trainer(network)
trainer.train(dataSet)
const output = network.activate([
14500, 17100, 72453,
4, 16650, 16650,
21701, 23262, 20991,
0, 3, 20991
])
console.log(output) // Should be 20991
I have run this code and made a few alterations to get to the current state, but as the output from the model, I always get [ 1 ]. Why is this?