Advertisement
RupeshAcharya60

Recommendation Algorithm

Apr 29th, 2023
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import pandas as pd
  2. from sklearn.neighbors import NearestNeighbors
  3.  
  4.  
  5. df = pd.read_csv('2020-4-27.csv')
  6. df.columns
  7. df.fillna(0, inplace=True)
  8. df_norm = (df[features] - df[features].mean()) / df[features].std()
  9. knn_model = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
  10. knn_model.fit(df_norm)
  11.  
  12.  
  13. def get_recommendations(query):
  14.     features = ["Price", "Bedroom", "Bathroom", "Floors", "Parking", "Year"]
  15.     query_df = pd.DataFrame(query, index=[0])
  16.     query_norm = (query_df[features] - df[features].mean()) / df[features].std()
  17.     distances, indices = knn_model.kneighbors(query_norm)
  18.     recommended_properties = df.loc[indices[0]][["Title", "Address", "Price","Area"]]
  19.     return recommended_properties
  20.  
  21.  
  22. query = {"Price": 20000000, "Bedroom": 3, "Bathroom": 4, "Floors": 2, "Parking": 1, "Year": 2013}
  23. recommended_properties = get_recommendations(query)
  24. print(recommended_properties)
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement