Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from sklearn.neighbors import NearestNeighbors
- df = pd.read_csv('2020-4-27.csv')
- df.columns
- df.fillna(0, inplace=True)
- df_norm = (df[features] - df[features].mean()) / df[features].std()
- knn_model = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
- knn_model.fit(df_norm)
- def get_recommendations(query):
- features = ["Price", "Bedroom", "Bathroom", "Floors", "Parking", "Year"]
- query_df = pd.DataFrame(query, index=[0])
- query_norm = (query_df[features] - df[features].mean()) / df[features].std()
- distances, indices = knn_model.kneighbors(query_norm)
- recommended_properties = df.loc[indices[0]][["Title", "Address", "Price","Area"]]
- return recommended_properties
- query = {"Price": 20000000, "Bedroom": 3, "Bathroom": 4, "Floors": 2, "Parking": 1, "Year": 2013}
- recommended_properties = get_recommendations(query)
- print(recommended_properties)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement