@@ -37,28 +37,36 @@ DataFrameStatsTest >> testCorrelationMatrix [
3737
3838 | expectedCorrelationMatrix actualCorrelationMatrix |
3939 expectedCorrelationMatrix := DataFrame withRows:
40- #( #( 1 0.311398 0.538922 0.454601 )
41- #( 0.311398 1 -0.321281 -0.308023 )
42- #( 0.538922 -0.321281 1 0.982956 )
43- #( 0.454601 -0.308023 0.982956
44- 1 ) ).
45- expectedCorrelationMatrix columnNames:
46- #( sepalLength sepalWidth petalLength petalWidth ) .
47- expectedCorrelationMatrix rowNames:
48- #( sepalLength sepalWidth petalLength petalWidth ) .
40+ #( #( 1 0.311398 0.538922 0.454601 ) #( 0.311398 1 -0.321281 -0.308023 ) #( 0.538922 -0.321281 1 0.982956 )
41+ #( 0.454601 -0.308023 0.982956 1 ) ).
42+ expectedCorrelationMatrix columnNames: #( sepalLength sepalWidth petalLength petalWidth ) .
43+ expectedCorrelationMatrix rowNames: #( sepalLength sepalWidth petalLength petalWidth ) .
4944 actualCorrelationMatrix := df correlationMatrix.
50- self
51- assert: actualCorrelationMatrix rowNames
52- equals: expectedCorrelationMatrix rowNames.
53- self
54- assert: actualCorrelationMatrix columnNames
55- equals: expectedCorrelationMatrix columnNames.
45+ self assert: actualCorrelationMatrix rowNames equals: expectedCorrelationMatrix rowNames.
46+ self assert: actualCorrelationMatrix columnNames equals: expectedCorrelationMatrix columnNames.
5647
5748 1 to: actualCorrelationMatrix numberOfColumns do: [ :j |
58- 1 to: actualCorrelationMatrix numberOfRows do: [ :i |
59- self
60- assert: (actualCorrelationMatrix at: i at: j)
61- closeTo: (expectedCorrelationMatrix at: i at: j) ] ]
49+ 1 to: actualCorrelationMatrix numberOfRows do: [ :i | self assert: (actualCorrelationMatrix at: i at: j) closeTo: (expectedCorrelationMatrix at: i at: j) ] ]
50+ ]
51+
52+ { #category : #tests }
53+ DataFrameStatsTest >> testCorrelationMatrixWithNils [
54+
55+ | expectedCorrelationMatrix actualCorrelationMatrix |
56+ df := DataFrame withRows: #( #( 1 1 ) #( 2 nil ) #( nil 3 ) #( 4 4 ) ).
57+ df columnNames: #( dogs cats ) .
58+
59+ expectedCorrelationMatrix := DataFrame withRows: #( #( 1 0.3207134902949093 ) #( 0.3207134902949093 1 ) ).
60+ expectedCorrelationMatrix columnNames: #( dogs cats ) .
61+ expectedCorrelationMatrix rowNames: #( dogs cats ) .
62+
63+ actualCorrelationMatrix := df correlationMatrix.
64+
65+ self assert: actualCorrelationMatrix rowNames equals: expectedCorrelationMatrix rowNames.
66+ self assert: actualCorrelationMatrix columnNames equals: expectedCorrelationMatrix columnNames.
67+
68+ 1 to: actualCorrelationMatrix numberOfColumns do: [ :j |
69+ 1 to: actualCorrelationMatrix numberOfRows do: [ :i | self assert: (actualCorrelationMatrix at: i at: j) closeTo: (expectedCorrelationMatrix at: i at: j) ] ]
6270]
6371
6472{ #category : #tests }
0 commit comments