Skip to content

Addition to Mission 155 Solution #112

Open

Description

@syed0019

The solution file didn't extract the optimal value for k in each model. Below is the code for the extraction of optimal k value:

import operator

two_feat_k_value = {}
three_feat_k_value = {}
four_feat_k_value = {}
five_feat_k_value = {}
six_feat_k_value = {}

dict_ = k_rmse_results.copy()

for k, v in dict_.items():
    for key,val in v.items():
        if k == '2 best features':
            two_feat_k_value[key] = val
        elif k == '3 best features':
            three_feat_k_value[key] = val
        elif k == '4 best features':
            four_feat_k_value[key] = val
        elif k == '5 best features':
            five_feat_k_value[key] = val
        else:
            six_feat_k_value[key] = val
            
print('Optimal k-values:')
print('two best features: {}'.format(min(two_feat_k_value.items(), key=operator.itemgetter(1))[1]))
print('three best features: {}'.format(min(three_feat_k_value.items(), key=operator.itemgetter(1))[1]))
print('four best features: {}'.format(min(four_feat_k_value.items(), key=operator.itemgetter(1))[1]))
print('five best features: {}'.format(min(five_feat_k_value.items(), key=operator.itemgetter(1))[1]))
print('six best features: {}'.format(min(six_feat_k_value.items(), key=operator.itemgetter(1))[1]))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions