Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ PMStandardizationScaler >> mean [

{ #category : #accessing }
PMStandardizationScaler >> scale [
^ self variance sqrt
^ self variance collect: [ :element |
| root |
root := element sqrt.
(root ~= 0) ifTrue: [ root ] ifFalse: [ 1.0 ]
]
]

{ #category : #transforming }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ PMStandardizationScalerTest >> testTransformAnotherMatrix [
self assert: (t transform: anotherMatrix) equals: (PMMatrix rows: #(#(3 3)))
]

{ #category : #tests }
PMStandardizationScalerTest >> testTransformConstantFeature [
| aMatrix t |
aMatrix := PMMatrix rows: #(#(8.0 0.0) #(8.0 0.0) #(8.0 1.0) #(8.0 1.0)).
t := PMStandardizationScaler new.
self assert: (t fitAndTransform: aMatrix) equals: (PMMatrix rows: #(#(0.0 -1.0) #(0.0 -1.0) #(0.0 1.0) #(0.0 1.0)))
]

{ #category : #tests }
PMStandardizationScalerTest >> testVariance [
| aMatrix t |
Expand All @@ -48,3 +56,15 @@ PMStandardizationScalerTest >> testVariance [
t fit: aMatrix.
self assert: t variance asArray closeTo: #(0.25 0.25)
]

{ #category : #tests }
PMStandardizationScalerTest >> testZeroScale [
"Tests if PMStandardizationScaler handles case when scale is 0, by changing it to 1.
Happens when one feature is constant eg: 8.0 in this test."

| aMatrix t |
aMatrix := PMMatrix rows: #((8.0 0.0) #(8.0 0.0) #(8.0 1.0) #(8.0 1.0)).
t := PMStandardizationScaler new.
t fit: aMatrix.
self assert: t scale asArray closeTo: #(1.0 0.5)
]