Issue
label with pandas (.map) in the following table
m2m_similarity.columns = ['MoviId 1','MoviId 2','similarity_score']
m2m_similarity.head(3)
I have tried to get the label slightly-similar, similar, and exacly
m2m_similarity['analysis'] = m2m_similarity['similarity_score'].map({
0.1: 'slightly-similar', 0.2: 'slightly-similar', 0.3: 'slightly-similar', 0.4: 'slightly-similar',
0.5: 'similar', 0.6: 'similar', 0.7: 'similar', 0.8: 'similar',0.9: 'similar',
1.0: 'Exacly'
})
m2m_similarity.head(3)
and the result is Nan
Solution
A better way would be:
m2m_similarity['analysis'] = m2m_similarity['similarity_score'].map(lambda s: 'Exacly' if round(s, 2) == 1 else ('similar' if round(s, 2) >= 0.5 else 'slightly-similar'))
As it would cover all the options in between.
And anyway make sure that in similarity_score
you have numbers and not strings
, and if they aren't actually high-precision floats that you only show the first digit.
Answered By - Aryerez
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.