docstr: Item Attribute KNN for Rating Prediction
  
  This algorithm predicts a rank for each user based on the similar items that he/her consumed,
  using a metadata or similarity pre-computed file
  
  Usage::
  
      >> ItemAttributeKNN(train, test, similarity_file=sim_matrix, as_similar_first=True).compute()
      >> ItemAttributeKNN(train, test, metadata_file=metadata, as_similar_first=False).compute()
  
  :param train_file: File which contains the train set. This file needs to have at least 3 columns
  (user item feedback_value).
  :type train_file: str, default None
  
  :param test_file: File which contains the test set. This file needs to have at least 3 columns
  (user item feedback_value).
  :type test_file: str, default None
  
  :param output_file: File with dir to write the final predictions
  :type output_file: str, default None
  
  :param metadata_file: File which contains the metadata set. This file needs to have at least 2 columns
  (item metadata).
  :type metadata_file: str, default None
  
  :param similarity_file: File which contains the similarity set. This file needs to have at least 3 columns
  (item item similarity).
  :type similarity_file: str, default None
  
  :param k_neighbors: Number of neighbors to use. If None, k_neighbor = int(sqrt(n_users))
  :type k_neighbors: int, default None
  
  :param as_similar_first: If True, for each unknown item, which will be predicted, we first look for its k
  most similar users and then take the intersection with the users that
  seen that item.
  :type as_similar_first: bool, default True
  
  :param metadata_as_binary: f True, the explicit value will be transform to binary
  :type metadata_as_binary: bool, default False
  
  :param metadata_similarity_sep: Delimiter for similarity or metadata file
  :type metadata_similarity_sep: str, default '   '
  
  :param similarity_metric: Pairwise metric to compute the similarity between the items. Reference about
  distances: http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.distance.pdist.html
  :type similarity_metric: str, default cosine
  
  :param sep: Delimiter for input files file
  :type sep: str, default '       '
  
  :param output_sep: Delimiter for output file
  :type output_sep: str, default '        '
docstr_tok: ["Item","Attribute","KNN","for","Rating","Prediction","This","algorithm","predicts","a","rank","for","each","user","based","on","the","similar","items","that","he\/her","consumed",",","using","a","metadata","or","similarity","pre-computed","file","Usage",":",":",">",">","ItemAttributeKNN","(","train",",","test",",","similarity_file=sim_matrix",",","as_similar_first=True",")",".compute","(",")",">",">","ItemAttributeKNN","(","train",",","test",",","metadata_file=metadata",",","as_similar_first=False",")",".compute","(",")",":","param","train_file",":","File","which","contains","the","train","set",".","This","file","needs","to","have","at","least","3","columns","(","user","item","feedback_value",")",".",":","type","train_file",":","str",",","default","None",":","param","test_file",":","File","which","contains","the","test","set",".","This","file","needs","to","have","at","least","3","columns","(","user","item","feedback_value",")",".",":","type","test_file",":","str",",","default","None",":","param","output_file",":","File","with","dir","to","write","the","final","predictions",":","type","output_file",":","str",",","default","None",":","param","metadata_file",":","File","which","contains","the","metadata","set",".","This","file","needs","to","have","at","least","2","columns","(","item","metadata",")",".",":","type","metadata_file",":","str",",","default","None",":","param","similarity_file",":","File","which","contains","the","similarity","set",".","This","file","needs","to","have","at","least","3","columns","(","item","item","similarity",")",".",":","type","similarity_file",":","str",",","default","None",":","param","k_neighbors",":","Number","of","neighbors","to","use",".","If","None",",","k_neighbor","=","int","(","sqrt","(","n_users",")",")",":","type","k_neighbors",":","int",",","default","None",":","param","as_similar_first",":","If","True",",","for","each","unknown","item",",","which","will","be","predicted",",","we","first","look","for","its","k","most","similar","users","and","then","take","the","intersection","with","the","users","that","seen","that","item",".",":","type","as_similar_first",":","bool",",","default","True",":","param","metadata_as_binary",":","f","True",",","the","explicit","value","will","be","transform","to","binary",":","type","metadata_as_binary",":","bool",",","default","False",":","param","metadata_similarity_sep",":","Delimiter","for","similarity","or","metadata","file",":","type","metadata_similarity_sep",":","str",",","default","'","'",":","param","similarity_metric",":","Pairwise","metric","to","compute","the","similarity","between","the","items",".","Reference","about","distances",":","http",":","\/\/docs.scipy.org\/doc\/scipy-0.14.0\/reference\/generated\/scipy.spatial.distance.pdist.html",":","type","similarity_metric",":","str",",","default","cosine",":","param","sep",":","Delimiter","for","input","files","file",":","type","sep",":","str",",","default","'","'",":","param","output_sep",":","Delimiter","for","output","file",":","type","output_sep",":","str",",","default","'","'"]
code: def __init__(
      self,
      train_file=None,
      test_file=None,
      output_file=None,
      metadata_file=None,
      similarity_file=None,
      k_neighbors=30,
      as_similar_first=True,
      metadata_as_binary=False,
      metadata_similarity_sep="\t",
      similarity_metric="cosine",
      sep="\t",
      output_sep="\t",
  ):
      """
      Item Attribute KNN for Rating Prediction
  
      This algorithm predicts a rank for each user based on the similar items that he/her consumed,
      using a metadata or similarity pre-computed file
  
      Usage::
  
          >> ItemAttributeKNN(train, test, similarity_file=sim_matrix, as_similar_first=True).compute()
          >> ItemAttributeKNN(train, test, metadata_file=metadata, as_similar_first=False).compute()
  
      :param train_file: File which contains the train set. This file needs to have at least 3 columns
      (user item feedback_value).
      :type train_file: str, default None
  
      :param test_file: File which contains the test set. This file needs to have at least 3 columns
      (user item feedback_value).
      :type test_file: str, default None
  
      :param output_file: File with dir to write the final predictions
      :type output_file: str, default None
  
      :param metadata_file: File which contains the metadata set. This file needs to have at least 2 columns
      (item metadata).
      :type metadata_file: str, default None
  
      :param similarity_file: File which contains the similarity set. This file needs to have at least 3 columns
      (item item similarity).
      :type similarity_file: str, default None
  
      :param k_neighbors: Number of neighbors to use. If None, k_neighbor = int(sqrt(n_users))
      :type k_neighbors: int, default None
  
      :param as_similar_first: If True, for each unknown item, which will be predicted, we first look for its k
      most similar users and then take the intersection with the users that
      seen that item.
      :type as_similar_first: bool, default True
  
      :param metadata_as_binary: f True, the explicit value will be transform to binary
      :type metadata_as_binary: bool, default False
  
      :param metadata_similarity_sep: Delimiter for similarity or metadata file
      :type metadata_similarity_sep: str, default '\t'
  
      :param similarity_metric: Pairwise metric to compute the similarity between the items. Reference about
      distances: http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.distance.pdist.html
      :type similarity_metric: str, default cosine
  
      :param sep: Delimiter for input files file
      :type sep: str, default '\t'
  
      :param output_sep: Delimiter for output file
      :type output_sep: str, default '\t'
  
      """
  
      super(ItemAttributeKNN, self).__init__(
          train_file=train_file,
          test_file=test_file,
          output_file=output_file,
          k_neighbors=k_neighbors,
          as_similar_first=as_similar_first,
          sep=sep,
          output_sep=output_sep,
          similarity_metric=similarity_metric,
      )
  
      self.recommender_name = "Item Attribute KNN Algorithm"
  
      self.metadata_file = metadata_file
      self.similarity_file = similarity_file
      self.metadata_as_binary = metadata_as_binary
      self.metadata_similarity_sep = metadata_similarity_sep
  
file_path: CaseRecommender/caserec/recommenders/rating_prediction/item_attribute_knn.py
imports: from collections import defaultdict
  import numpy
  from caserec.recommenders.rating_prediction.itemknn import ItemKNN
  from caserec.utils.process_data import ReadFile
label_desc: Use image node_id 1 to create a new ItemAttributeKNN object from inherited base classes: ItemKNN with example: obj = ItemAttributeKNN(train_file, test_file, output_file, metadata_file, similarity_file, k_neighbors, as_similar_first, metadata_as_binary, metadata_similarity_sep, similarity_metric, sep, output_sep)