xy-scale 1.1.8 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/datasets.js +44 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xy-scale",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "main": "./index.js",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/datasets.js CHANGED
@@ -7,7 +7,8 @@ export const parseTrainingXY = ({
7
7
  trainingSplit = 0.8,
8
8
  repeat = {},
9
9
  yCallbackFunc,
10
- xCallbackFunc,
10
+ xCallbackFunc,
11
+ validateRows = row => row,
11
12
  groups,
12
13
  shuffle = false,
13
14
  minmaxRange,
@@ -18,6 +19,9 @@ export const parseTrainingXY = ({
18
19
 
19
20
  //if parsedX and parsedY is undefined or null the current row will be excluded from training or production
20
21
  for (let x = 0; x < arrObj.length; x++) {
22
+
23
+ if(!validateRows(arrObj[x])) continue
24
+
21
25
  const parsedX = xCallbackFunc({ objRow: arrObj, index: x });
22
26
  const parsedY = yCallbackFunc({ objRow: arrObj, index: x });
23
27
 
@@ -48,37 +52,46 @@ export const parseTrainingXY = ({
48
52
  } = scaleArrayObj({arrObj: Y, repeat, groups, minmaxRange})
49
53
 
50
54
 
51
- if(balancing)
52
- {
53
- let balance
54
55
 
55
- if(balancing === 'oversample')
56
- {
57
- balance = oversampleXY(scaledX, scaledY)
58
- scaledX = balance.X
59
- scaledY = balance.Y
60
- }
61
- else if(balancing === 'undersample')
62
- {
63
- balance = undersampleXY(scaledX, scaledY)
64
- scaledX = balance.X
65
- scaledY = balance.Y
66
- }
67
- else
68
- {
69
- throw Error('balancing argument only accepts "false", "oversample" and "undersample". Defaults to "false".')
70
- }
71
- }
72
56
 
73
57
 
74
58
  const splitIndex = Math.floor(scaledX.length * trainingSplit)
75
59
 
60
+ let trainX = scaledX.slice(0, splitIndex)
61
+ let trainY = scaledY.slice(0, splitIndex)
62
+ let testX = scaledX.slice(splitIndex)
63
+ let testY = scaledY.slice(splitIndex)
64
+
65
+
66
+ if(balancing)
67
+ {
68
+ let balance
69
+
70
+ if(balancing === 'oversample')
71
+ {
72
+ balance = oversampleXY(trainX, trainY)
73
+ trainX = balance.X
74
+ trainY = balance.Y
75
+ }
76
+ else if(balancing === 'undersample')
77
+ {
78
+ balance = undersampleXY(trainX, trainY)
79
+ trainX = balance.X
80
+ trainY = balance.Y
81
+ }
82
+ else
83
+ {
84
+ throw Error('balancing argument only accepts "false", "oversample" and "undersample". Defaults to "false".')
85
+ }
86
+ }
87
+
88
+
76
89
  // Split into training and testing sets
77
90
  return {
78
- trainX: scaledX.slice(0, splitIndex),
79
- trainY: scaledY.slice(0, splitIndex),
80
- testX: scaledX.slice(splitIndex),
81
- testY: scaledY.slice(splitIndex),
91
+ trainX,
92
+ trainY,
93
+ testX,
94
+ testY,
82
95
 
83
96
  configX,
84
97
  keyNamesX,
@@ -91,7 +104,8 @@ export const parseTrainingXY = ({
91
104
  export const parseProductionX = ({
92
105
  arrObj,
93
106
  repeat = {},
94
- xCallbackFunc,
107
+ xCallbackFunc,
108
+ validateRows = row => row,
95
109
  groups,
96
110
  shuffle = false,
97
111
  minmaxRange
@@ -99,7 +113,10 @@ export const parseProductionX = ({
99
113
  let X = [];
100
114
 
101
115
  for (let x = 0; x < arrObj.length; x++) {
102
- const parsedX = xCallbackFunc({ objRow: arrObj, index: x })
116
+
117
+ if(!validateRows(arrObj[x])) continue
118
+
119
+ const parsedX = xCallbackFunc({ objRow: arrObj, index: x})
103
120
 
104
121
  if (parsedX) {
105
122
  X.push(parsedX)