Skip to content

Commit 0e82757

Browse files
committed
fix: testing for multi feature linear regression model
1 parent 33b11da commit 0e82757

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/cli/multi-feature.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default async function multiFeatureProcess(data) {
101101
const a = (sumY / data.length) - sumSlopeiXi
102102

103103
// Equation result
104-
const y = (...x) => a + slopes.reduce((sum, val, index) => sum + (val * x[index]))
104+
const y = (x) => a + slopes.reduce((sum, val, index) => sum + (val * x[index]))
105105

106106

107107
// Print the equation
@@ -112,11 +112,11 @@ export default async function multiFeatureProcess(data) {
112112
if (index != slopes.length - 1) process.stdout.write(chalk.blueBright(' + '))
113113
})
114114

115-
115+
print('\n\r')
116116

117117
if (await confirm({ message: 'Do you want to test?'})) {
118118
do {
119-
await testing(y, answers.feature, answers.label)
119+
await testing(y, answers.features, answers.label)
120120
} while (await confirm({ message: 'Do you want to test again?'}));
121121
}
122122

@@ -125,9 +125,17 @@ export default async function multiFeatureProcess(data) {
125125
}
126126

127127

128-
async function testing(y, feature, label) {
129-
const inputFeature = await input({message: `Input ${feature}`})
130-
print(`Prediction ${label}: ${y(inputFeature)}`)
128+
async function testing(y, features, label) {
129+
const inputInquirer = features.map(feature => {
130+
return {
131+
type: 'number',
132+
name: feature,
133+
message: `Input ${feature}`
134+
}
135+
})
136+
137+
const inputFeatures = await inquirer.prompt(inputInquirer)
138+
print(`Prediction ${label}:`, chalk.blueBright(`${y(Object.values(inputFeatures))}`))
131139
}
132140

133141

0 commit comments

Comments
 (0)