Code Monkey home page Code Monkey logo

pycollaborativefiltering's Introduction

pyCollaborativeFiltering

User-based and Item-based Collaborative Filtering algorithms written in Python

Develop enviroment

  • Language: Python3
  • IDE: Eclipse PyDev
  • Prerequisite libraries: Numpy

Specification of user-based method

  • If you use a built-up model, the recommender system considers only the nearest neighbors existing in the model. Otherwise, the recommender looks for K-similar neighbors for each target user by using the given similarity measure and the number(K) of nearest neighbors.
  • In unary data, the predicted score of the item is the average similarity of the nearest neighbors who rated on the item.
  • User similarity does not include those of neighbors whose similarity is zero or lower value.
  • The cosine similarity basically considers only co-rated items. (Another measures such as the basic cosine similarity and Pearson correlation coefficient are also applicable.)

Input data format

UserID \t ItemID \t Rating \n

Usage example

User-based Recommendation

>>> import tool
>>> data = tool.loadData("/home/changuk/data/MovieLens/movielens.dat")
>>> from recommender import UserBased
>>> ubcf = UserBased()
>>> ubcf.loadData(data)
>>> import similarity
>>> simMeasure = similarity.cosine_intersection
>>> for user in data.keys():
...     recommendation = ubcf.Recommendation(user, simMeasure=simMeasure, nNeighbors=30)

Item-based Recommendation

>>> import tool
>>> data = tool.loadData("/home/changuk/data/MovieLens/movielens.dat")
>>> from recommender import ItemBased
>>> ibcf = ItemBased()
>>> ibcf.loadData(data)
>>> model = ibcf.buildModel(nNeighbors=20)
>>> for user in data.keys():
...     recommendation = ibcf.Recommendation(user, model=model)

Validation

>>> import tool
>>> trainSet = tool.loadData("/home/changuk/data/MovieLens/u1.base")
>>> testSet = tool.loadData("/home/changuk/data/MovieLens/u1.test")
>>> from recommender import UserBased
>>> ubcf = UserBased()
>>> ubcf.loadData(trainSet)
>>> model = ubcf.buildModel(nNeighbors=30)
>>> import validation
>>> result = validation.evaluateRecommender(testSet, ubcf, model=model, topN=10)
>>> print(result)
{'Precision': 0.050980392156862, 'Recall': 0.009698538130460, 'Hit-rate': 0.5098039215686}

TODO list

  • Support binary data
  • Implement similarity normalization in Item-based CF

References

pycollaborativefiltering's People

Contributors

changuk avatar

Watchers

Yuan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.