<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Tutorial
Step1:  Load example data
OpenMRS provides a small set of user ratings data. Let's load it and see what's in there.
Step2:  Start and train a recomemndation engine
Feed the user ratings data into the recommendation engine and train it with collaborative filtering.
Step3:  Now the recommendation engine knows about users and their ratings. We can retrieve and print them out.
Step4:  Generate recommendations
With the trained engine, we can let it generate music recommendations for a user according to his/her historical ratings.
<ASSISTANT_TASK:>
Python Code:
try:
    import OpenMRS as om
except:
    # At this point, you probably haven't installed OpenMRS. You can install it by:
    #   sudo pip install git+https://github.com/BerryAI/Acai
    # Now we are going to import OpenMRS from the source.
    # Note: This assumes you are currently in the 'examples/' folder running this notebook.
    import os
    import sys
    CWD = os.getcwd()
    print 'current working directory:', CWD
    sys.path.append(os.path.join(CWD, '..'))
    import OpenMRS as om
Explanation: Tutorial: using OpenMRS to recommend music for a listener
Prerequisites
Please make sure you have installed the following packages:
numpy
sklearn
Import OpenMRS library
End of explanation
example_ratings = om.data.get_example_ratings()
example_tracks = om.data.get_example_tracks()
print 'These are user ids:'
print example_ratings.keys()[:5]
print 'These are track ids and rating scores for the first user:'
print example_ratings.values()[0].items()[:5]
Explanation: Load example data
OpenMRS provides a small set of user ratings data. Let's load it and see what's in there.
End of explanation
engine = om.RecommendationEngine()  # or equivalently, use the following line
# engine = om.RecommendationEngine(catalog=SimpleCatalog(example_tracks))
# Feed the user ratings into the recommendation engine and train it.
engine.train(ratings=example_ratings)
Explanation: Start and train a recomemndation engine
Feed the user ratings data into the recommendation engine and train it with collaborative filtering.
End of explanation
one_user = engine.get_user_ids()[0]
ratings = engine.get_ratings_by_user(user_id=one_user)
print ('Ratings by user %s (5 being most favorable and 1 least favorable):' %
    one_user)
for track_id, rating in ratings.items()[:5]:
    print '  User rates %s on track %s' % (rating,
        engine.catalog.get_track_by_id(track_id))
Explanation: Now the recommendation engine knows about users and their ratings. We can retrieve and print them out.
End of explanation
# Recommend tracks for a user.
recommended_tracks = engine.recommend(user_id=one_user, num=10)
print '\nRecommended tracks for user %s:' % one_user
for t in recommended_tracks:
    print t
Explanation: Generate recommendations
With the trained engine, we can let it generate music recommendations for a user according to his/her historical ratings.
End of explanation
<END_TASK>