<jupyter_start><jupyter_text>[View in Colaboratory](https://colab.research.google.com/github/shashank2806/Apna-Broker-API/blob/master/Banglore_house_rent_prediction.ipynb)<jupyter_code>from google.colab import files
files.upload()
!unzip "hackathon_rentomter_nobroker.csv.zip"
import pandas as pd
import pickle
data = pd.read_csv('hackathon_rentomter_nobroker.csv')
features_corelated = ['longitude', 'latitude', 'gym', 'lift', 'swimming_pool', 'property_size', 'bathroom', 'floor', 'total_floor', 'balconies', 'building_type', 'parking', 'type']
y = data['rent']
one_hot_encoded_features = pd.get_dummies(data[features_corelated])
one_hot_encoded_features.describe()
# Split into validation and training data
from sklearn.model_selection import train_test_split
train_X, val_X, train_y, val_y = train_test_split(one_hot_encoded_features, y, test_size=0.2)


from xgboost import XGBRegressor

xgb_model = XGBRegressor(n_estimators=1000, learning_rate=0.05)
xgb_model.fit(train_X, train_y, early_stopping_rounds=5, 
             eval_set=[(val_X, val_y)], verbose=False)
val_predictions = xgb_model.predict(val_X)



from sklearn.metrics import mean_absolute_error
train_accuracy = xgb_model.score(train_X, train_y)
val_accuracy = xgb_model.score(val_X, val_y)
print('train_accuracy: ',train_accuracy)
print('val_accuracy: ',val_accuracy)
# save model
# save the classifier
with open('model.pkl', 'wb') as fid:
    pickle.dump(xgb_model, fid)    

# load it again
with open('model.pkl', 'rb') as fid:
    xgb_model_saved = pickle.load(fid)
!ls
files.download('model.pkl')
data[features_corelated].head()
data.iloc[0]
one_hot_encoded_features.columns
one_hot_encoded_features.describe(include='all')
val_X.iloc[0], val_y.iloc[0]
xgb_model.predict(val_X.iloc[0:1])
val_X.iloc[0:1].shape
import numpy as np
qw = np.array([1,2])
qw.shape
c = pd.DataFrame([77,12,0,0,0,500,1,1,2,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0])
c=c.transpose()
c.shape
c.columns = one_hot_encoded_features.columns
xgb_model.predict(c)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13784584980237155, 'fraction_numerical': 0.025197628458498024, 'mean_word_length': 7.728448275862069, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '518401', 'license': 'MIT', 'n_tokens_mistral': 833, 'n_tokens_neox': 802, 'n_words': 128, 'path': 'house_rent_prediction.ipynb', 'repo_name': 'CoDeRgAnEsh/Rent-flask', 'size': '2024'}