code: import pandas as pd
  import matplotlib
  import matplotlib.pyplot as plt
  from sklearn.metrics.pairwise import pairwise_distances
  import numpy as np
  
  # pass in column names for each CSV as the column name is not given in the file and read them using pandas.
  # You can check the column names from the readme file
  
  #Reading users file:
  u_cols = ['user_id', 'age', 'sex', 'occupation', 'zip_code']
  users = pd.read_csv('ml-100k/u.user', sep='|', names=u_cols,encoding='latin-1')
  
  #Reading ratings file:
  r_cols = ['user_id', 'movie_id', 'rating', 'unix_timestamp']
  ratings = pd.read_csv('ml-100k/u.data', sep='\t', names=r_cols,encoding='latin-1')
  
  #Reading items file:
  i_cols = ['movie id', 'movie title' ,'release date','video release date', 'IMDb URL', 'unknown', 'Action', 'Adventure',
  'Animation', 'Children\'s', 'Comedy', 'Crime', 'Documentary', 'Drama', 'Fantasy',
  'Film-Noir', 'Horror', 'Musical', 'Mystery', 'Romance', 'Sci-Fi', 'Thriller', 'War', 'Western']
  items = pd.read_csv('ml-100k/u.item', sep='|', names=i_cols,
  encoding='latin-1')
  
  print(users.shape)
  users.head()
  
  items.head()
  
  r_cols = ['user_id', 'movie_id', 'rating', 'unix_timestamp']
  ratings_train = pd.read_csv('ml-100k/ua.base', sep='\t', names=r_cols, encoding='latin-1')
  ratings_test = pd.read_csv('ml-100k/ua.test', sep='\t', names=r_cols, encoding='latin-1')
  print(ratings_train.shape, ratings_test.shape)
  
  n_users = ratings.user_id.unique().shape[0]
  n_items = ratings.movie_id.unique().shape[0]
  
  #Create Matrices:
  data_matrix = np.zeros((n_users, n_items))
  for line in ratings.itertuples():
      data_matrix[line[1]-1, line[2]-1] = line[3]
  
  #pairwise distance function:
  user_similarity = pairwise_distances(data_matrix, metric='cosine')
  item_similarity = pairwise_distances(data_matrix.T, metric='cosine')
  
  def predict(ratings, similarity, type='user'):
      if type == 'user':
          mean_user_rating = ratings.mean(axis=1)
          #We use np.newaxis so that mean_user_rating has same format as ratings
          ratings_diff = (ratings - mean_user_rating[:, np.newaxis])
          pred = mean_user_rating[:, np.newaxis] + similarity.dot(ratings_diff) / np.array([np.abs(similarity).sum(axis=1)]).T
      elif type == 'item':
          pred = ratings.dot(similarity) / np.array([np.abs(similarity).sum(axis=1)])
      return pred
  
  user_prediction = predict(data_matrix, user_similarity, type='user')
  item_prediction = predict(data_matrix, item_similarity, type='item')
apis: pandas.read_csv numpy.abs numpy.zeros sklearn.metrics.pairwise.pairwise_distances