@@ -66,3 +66,103 @@ def test_valid_name_and_description(self):
66
66
descriptor [0 ].description
67
67
== "This model was trained on data collected from a potentially biased source."
68
68
)
69
+
70
+ def test_log_user_with_description_to_considerations_section (self ):
71
+ """Test log_user with description to considerations section."""
72
+ self .model_card_report .log_user (description = "This is a user description" )
73
+ assert len (self .model_card_report ._model_card .considerations .users ) == 1
74
+ assert (
75
+ self .model_card_report ._model_card .considerations .users [0 ].description
76
+ == "This is a user description"
77
+ )
78
+
79
+ def test_log_performance_metric (self ):
80
+ """Test log_performance_metric."""
81
+ self .model_card_report .log_quantitative_analysis (
82
+ analysis_type = "performance" ,
83
+ name = "accuracy" ,
84
+ value = 0.85 ,
85
+ metric_slice = "test" ,
86
+ decision_threshold = 0.8 ,
87
+ description = "Accuracy of the model on the test set" ,
88
+ pass_fail_thresholds = [0.9 , 0.85 , 0.8 ],
89
+ pass_fail_threshold_fns = [lambda x , t : x >= t for _ in range (3 )],
90
+ )
91
+ assert (
92
+ self .model_card_report ._model_card .quantitative_analysis .performance_metrics [
93
+ 0
94
+ ].type
95
+ == "accuracy"
96
+ )
97
+ assert (
98
+ self .model_card_report ._model_card .quantitative_analysis .performance_metrics [
99
+ 0
100
+ ].value
101
+ == 0.85
102
+ )
103
+ assert (
104
+ self .model_card_report ._model_card .quantitative_analysis .performance_metrics [
105
+ 0
106
+ ].slice
107
+ == "test"
108
+ )
109
+ assert (
110
+ self .model_card_report ._model_card .quantitative_analysis .performance_metrics [
111
+ 0
112
+ ].decision_threshold
113
+ == 0.8
114
+ )
115
+ assert (
116
+ self .model_card_report ._model_card .quantitative_analysis .performance_metrics [
117
+ 0
118
+ ].description
119
+ == "Accuracy of the model on the test set"
120
+ )
121
+ assert (
122
+ len (
123
+ self .model_card_report ._model_card .quantitative_analysis .performance_metrics [
124
+ 0
125
+ ].tests ,
126
+ )
127
+ == 3
128
+ )
129
+
130
+ def test_log_quantitative_analysis_performance (self ):
131
+ """Test log_quantitative_analysis (performance)."""
132
+ self .model_card_report .log_quantitative_analysis (
133
+ analysis_type = "performance" ,
134
+ name = "accuracy" ,
135
+ value = 0.85 ,
136
+ )
137
+ assert (
138
+ self .model_card_report ._model_card .quantitative_analysis .performance_metrics [
139
+ 0
140
+ ].type
141
+ == "accuracy"
142
+ )
143
+ assert (
144
+ self .model_card_report ._model_card .quantitative_analysis .performance_metrics [
145
+ 0
146
+ ].value
147
+ == 0.85
148
+ )
149
+
150
+ def test_log_quantitative_analysis_fairness (self ):
151
+ """Test log_quantitative_analysis (fairness)."""
152
+ self .model_card_report .log_quantitative_analysis (
153
+ analysis_type = "fairness" ,
154
+ name = "disparate_impact" ,
155
+ value = 0.9 ,
156
+ )
157
+ assert (
158
+ self .model_card_report ._model_card .fairness_analysis .fairness_reports [
159
+ 0
160
+ ].type
161
+ == "disparate_impact"
162
+ )
163
+ assert (
164
+ self .model_card_report ._model_card .fairness_analysis .fairness_reports [
165
+ 0
166
+ ].value
167
+ == 0.9
168
+ )
0 commit comments