Dec-06-2019, 08:01 AM
deadeye@nexus ~ $ ipython Python 3.8.0 (default, Oct 15 2019, 17:33:09) Type 'copyright', 'credits' or 'license' for more information IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: data = {'253.0': {'precision': 0.8333333333333334, 'recall': 0.375, 'f1-score': 0.5172413793103448, 'support': 80}, '305.0': {'precision': 0.8132780082987552, 'recall': 0.965517241 ...: 3793104, 'f1-score': 0.882882882882883, 'support': 203}, '308.0': {'precision': 0.9594594594594594, 'recall': 0.9861111111111112, 'f1-score': 0.9726027397260274, 'support': 216}, ' ...: accuracy': 0.8797595190380761, 'macro avg': {'precision': 0.8686902670305159, 'recall': 0.7755427841634739, 'f1-score': 0.7909090006397518, 'support': 499}, 'weighted avg': {'preci ...: sion': 0.8797702316524192, 'recall': 0.8797595190380761, 'f1-score': 0.8630996540097691, 'support': 499}} In [2]: data.keys() Out[2]: dict_keys(['253.0', '305.0', '308.0', 'accuracy', 'macro avg', 'weighted avg']) In [3]: data['253.0'] Out[3]: {'precision': 0.8333333333333334, 'recall': 0.375, 'f1-score': 0.5172413793103448, 'support': 80} In [4]: data.keys() - ('accuracy', 'macro avg', 'weighted avg') Out[4]: {'253.0', '305.0', '308.0'} In [5]: for value, subdict in data.keys() - ('accuracy', 'macro avg', 'weighted avg'): ...: print(f'{value} -> {subdict}') ...: --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-5-6c08b0dd40e7> in <module> ----> 1 for value, subdict in data.keys() - ('accuracy', 'macro avg', 'weighted avg'): 2 print(f'{value} -> {subdict}') 3 ValueError: too many values to unpack (expected 2) In [6]: for key in data.keys() - ('accuracy', 'macro avg', 'weighted avg'): ...: print(f'{key} -> {data[key]}') ...: ...: 308.0 -> {'precision': 0.9594594594594594, 'recall': 0.9861111111111112, 'f1-score': 0.9726027397260274, 'support': 216} 305.0 -> {'precision': 0.8132780082987552, 'recall': 0.9655172413793104, 'f1-score': 0.882882882882883, 'support': 203} 253.0 -> {'precision': 0.8333333333333334, 'recall': 0.375, 'f1-score': 0.5172413793103448, 'support': 80} In [7]: for key in data.keys() - ('accuracy', 'macro avg', 'weighted avg'): ...: print(f'{key} -> Precision: {data[key]['precision']}') ...: ...: File "<ipython-input-7-2e54305704fb>", line 2 print(f'{key} -> Precision: {data[key]['precision']}') ^ SyntaxError: invalid syntax In [8]: for key in data.keys() - ('accuracy', 'macro avg', 'weighted avg'): ...: print(f'{key} -> Precision: {data[key]["precision"]}') ...: ...: 308.0 -> Precision: 0.9594594594594594 305.0 -> Precision: 0.8132780082987552 253.0 -> Precision: 0.8333333333333334Just play with you dict. You have keys, which are numbers as
str
and 3 other keys.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!