Skip to content

Commit 1e17b61

Browse files
committed
change parseInt to parseFloat for better accuracy
1 parent 67bbb8a commit 1e17b61

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/cli/single-feature.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ export default async function singleFeatureProcess(data) {
8080
* @returns {function(x): number} a function of linear equation
8181
*/
8282
function modelling(data, answers) {
83-
const sumX = data.reduce((sum, val) => sum + parseInt(val[answers.feature]), 0)
84-
const sumY = data.reduce((sum, val) => sum + parseInt(val[answers.label]), 0)
85-
const sumXY = data.reduce((sum, val) => sum + (parseInt(val[answers.feature]) * parseInt(val[answers.label])), 0)
86-
const sumXSquared = data.reduce((sum, val) => sum + parseInt(val[answers.feature]) ** 2, 0)
83+
const sumX = data.reduce((sum, val) => sum + parseFloat(val[answers.feature]), 0)
84+
const sumY = data.reduce((sum, val) => sum + parseFloat(val[answers.label]), 0)
85+
const sumXY = data.reduce((sum, val) => sum + (parseFloat(val[answers.feature]) * parseFloat(val[answers.label])), 0)
86+
const sumXSquared = data.reduce((sum, val) => sum + parseFloat(val[answers.feature]) ** 2, 0)
8787
const sumXTimesSumY = sumX * sumY
8888

8989
const b = (

0 commit comments

Comments
 (0)