zoukankan      html  css  js  c++  java
  • Book Recommendation Engine using KNN

    Book Recommendation Engine using KNN

    https://www.freecodecamp.org/learn/machine-learning-with-python/machine-learning-with-python-projects/book-recommendation-engine-using-knn

    In this challenge, you will create a book recommendation algorithm using K-Nearest Neighbors.

    You will use the Book-Crossings dataset. This dataset contains 1.1 million ratings (scale of 1-10) of 270,000 books by 90,000 users.

    You can access the full project instructions and starter code on Google Colaboratory.

    Pandas

    https://www.cnblogs.com/beyondChan/p/10861045.html

    https://www.cnblogs.com/feily/p/14397470.html

    NearestNeighbors

    Unsupervised learner for implementing neighbor searches.

    Read more in the User Guide.

    Examples
    >>>
    
    >>> import numpy as np
    >>> from sklearn.neighbors import NearestNeighbors
    >>> samples = [[0, 0, 2], [1, 0, 0], [0, 0, 1]]
    
    >>>
    
    >>> neigh = NearestNeighbors(n_neighbors=2, radius=0.4)
    >>> neigh.fit(samples)
    NearestNeighbors(...)
    
    >>>
    
    >>> neigh.kneighbors([[0, 0, 1.3]], 2, return_distance=False)
    array([[2, 0]]...)
    
    >>>
    
    >>> nbrs = neigh.radius_neighbors(
    ...    [[0, 0, 1.3]], 0.4, return_distance=False
    ... )
    >>> np.asarray(nbrs[0][0])
    array(2)

    参考

    https://datascienceplus.com/building-a-book-recommender-system-the-basics-knn-and-matrix-factorization/

    使用 pivot 建立二维虚拟视图。

    us_canada_user_rating = us_canada_user_rating.drop_duplicates(['userID', 'bookTitle'])
    us_canada_user_rating_pivot = us_canada_user_rating.pivot(index = 'bookTitle', columns = 'userID', values = 'bookRating').fillna(0)
    us_canada_user_rating_matrix = csr_matrix(us_canada_user_rating_pivot.values)
    
    from sklearn.neighbors import NearestNeighbors
    
    model_knn = NearestNeighbors(metric = 'cosine', algorithm = 'brute')
    model_knn.fit(us_canada_user_rating_matrix)



    query_index = np.random.choice(us_canada_user_rating_pivot.shape[0])
    distances, indices = model_knn.kneighbors(us_canada_user_rating_pivot.iloc[query_index, :].reshape(1, -1), n_neighbors = 6)
    
    for i in range(0, len(distances.flatten())):
        if i == 0:
            print('Recommendations for {0}:
    '.format(us_canada_user_rating_pivot.index[query_index]))
        else:
            print('{0}: {1}, with distance of {2}:'.format(i, us_canada_user_rating_pivot.index[indices.flatten()[i]], distances.flatten()[i]))

    https://zhuanlan.zhihu.com/p/29903232

    https://github.com/BUVANEASH/Book-Recommendation---Collaborative-Filtering

    https://github.com/jalajthanaki/Book_recommendation_system/blob/master/KNN_based_recommendation_system.ipynb

    出处:http://www.cnblogs.com/lightsong/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
  • 相关阅读:
    struts2:JSP页面及Action中获取HTTP参数(parameter)的几种方式
    Wcf 双工通信的应用
    较完整的轮播图特效
    jQuery图片轮播的具体实现
    一种新的隐藏-显示模式诞生——css3的scale(0)到scale(1)
    你所不知的 CSS ::before 和 ::after 伪元素用法
    scale等比缩放才能做到看上去能让线条以中心点展开
    loading.io一个可以直接生成loading gif图标的站点
    按住ctrl键可以在新窗口打开图片
    背景图片等比缩放的写法background-size简写法
  • 原文地址:https://www.cnblogs.com/lightsong/p/14746914.html
Copyright © 2011-2022 走看看