992 gen = cls._yield_score_metrics(
993 predict_returns, target_values, target_variable
994 )
995 return [metric for metric in gen] 996 # Multiclass classification models
997 elif len(target_values) > 2:
998 if predict_returns.count(True) > 1:
1009 gen = cls._yield_score_metrics(
1010 predict_returns, target_values, target_variable
1011 )
1012 return [metric for metric in gen]1013
1014 @staticmethod
1015 def _yield_score_metrics(
It is unnecessary to use a comprehension just to loop over the iterable
and create a list
/set
/dict
out of it.
Python has a specialized set of tools for this task: the list
/set
/dict
constructors, which are faster and more readable.
states = [
('AL', 'Alabama'),
('AK', 'Alaska'),
('AZ', 'Arizona'),
('AR', 'Arkansas'),
('CA', 'California'),
# ...
]
abbreviations_to_names = {
abbreviation: name
for abbreviation, name in states
}
states = [
('AL', 'Alabama'),
('AK', 'Alaska'),
('AZ', 'Arizona'),
('AR', 'Arkansas'),
('CA', 'California'),
# ...
]
abbreviations_to_names = dict(states)