Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

knn - when I run the code below,I am getting an error as "index 0 is out of bounds for axis 0 with size 0"

This is my code below

def recomend_book(book_name):
    b_id = np.where(books_rating_pivot.index == book_name)[0][0]
    _, recommendations = model.kneighbors(books_rating_pivot.iloc[b_id,:].values.reshape(1,-1))
    for i in range(len(recommendations)):
        if i == 0:
            print(f"For book "{book_name}" is recommended")
            if not i:
                print(books_rating_pivot.index[recommendations[i]])

recomend_book('Harry')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...