Skip to content

Commit a43aa18

Browse files
committed
Add a way to speedup dataframe data imputing
1 parent 752871b commit a43aa18

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/AI-DataImputers/AISimpleImputer.class.st

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,7 @@ AISimpleImputer >> transform: aCollection [
176176
self ensureIs2D: aCollection.
177177
self statistics ifNil: [ self error: '#fit: needs to be called before transforming.' ].
178178

179-
^ aCollection collect: [ :subcoll |
180-
subcoll withIndexCollect: [ :elem :index |
181-
elem = self missingValue
182-
ifTrue: [ statistics at: index ]
183-
ifFalse: [ elem ] ] ]
179+
^ aCollection copyReplace: missingValue in2DCollectionBy: statistics
184180
]
185181

186182
{ #category : #options }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Extension { #name : #SequenceableCollection }
2+
3+
{ #category : #'*AI-DataImputers' }
4+
SequenceableCollection >> copyReplace: missingValue in2DCollectionBy: arrayOfReplacementValues [
5+
"I am a 2D collection and the goal is to return a copy replace the missing values by the values of my second parameter. The good value is the index of the missing value in the sub collection."
6+
7+
^ self collect: [ :subColl |
8+
subColl withIndexCollect: [ :element :index |
9+
element = missingValue
10+
ifTrue: [ arrayOfReplacementValues at: index ]
11+
ifFalse: [ element ] ] ]
12+
]

0 commit comments

Comments
 (0)