11import process from 'process'
22import chalk from 'chalk'
33import inquirer from 'inquirer'
4- import { input , confirm } from '@inquirer/prompts'
4+ import { confirm } from '@inquirer/prompts'
55
66
77
@@ -47,14 +47,25 @@ export default async function multiFeatureProcess(data) {
4747 }
4848
4949
50- // const numberPattern = /^[+-]?\d+(\.\d+)?$/
51- // for (const item of data) {
52- // if (!numberPattern.test(item[answers.features]) || !numberPattern.test(item[answers.label])) {
53- // print(chalk.redBright('\n[!] Some data is not a number! Unable to process further!'))
54- // await confirm({ message: 'Continue?'})
55- // return;
56- // }
57- // }
50+ /**
51+ * Raw data validation. Make sure all feature and label are number
52+ */
53+ const numberPattern = / ^ [ + - ] ? \d + ( \. \d + ) ? $ /
54+ for ( const item of data ) {
55+ if ( ! numberPattern . test ( item [ answers . label ] ) ) {
56+ print ( chalk . redBright ( '\n[!] Some data is not a number! Unable to process further!' ) )
57+ await confirm ( { message : 'Continue?' } )
58+ return ;
59+ }
60+
61+ for ( const feature of answers . features ) {
62+ if ( ! numberPattern . test ( item [ feature ] ) ) {
63+ print ( chalk . redBright ( '\n[!] Some data is not a number! Unable to process further!' ) )
64+ await confirm ( { message : 'Continue?' } )
65+ return ;
66+ }
67+ }
68+ }
5869
5970
6071 /**
@@ -91,12 +102,12 @@ export default async function multiFeatureProcess(data) {
91102 /**
92103 * INSPECTION!
93104 */
94- print ( 'sumY: ' , sumY )
95- print ( 'sumXi: ' , sumXi )
96- print ( 'slopes: ' , slopes )
97- print ( 'sumXiSquare: ' , sumXiSquared )
98- print ( 'sumAllXiSquared: ' , sumAllXiSquared )
99- print ( 'sumXiYi: ' , sumXiYi )
105+ // print('sumY: ', sumY)
106+ // print('sumXi: ', sumXi)
107+ // print('slopes: ', slopes)
108+ // print('sumXiSquare: ', sumXiSquared)
109+ // print('sumAllXiSquared: ', sumAllXiSquared)
110+ // print('sumXiYi: ', sumXiYi)
100111
101112 const a = ( sumY / data . length ) - sumSlopeiXi
102113
@@ -119,9 +130,6 @@ export default async function multiFeatureProcess(data) {
119130 await testing ( y , answers . features , answers . label )
120131 } while ( await confirm ( { message : 'Do you want to test again?' } ) ) ;
121132 }
122-
123-
124- evaluation ( )
125133}
126134
127135
@@ -137,9 +145,3 @@ async function testing(y, features, label) {
137145 const inputFeatures = await inquirer . prompt ( inputInquirer )
138146 print ( `Prediction ${ label } :` , chalk . blueBright ( `${ y ( Object . values ( inputFeatures ) ) } ` ) )
139147}
140-
141-
142- function evaluation ( ) {
143- print ( 'Evaluation!' )
144- print ( 'MSE, MAE, RMSE' )
145- }
0 commit comments