<jupyter_start><jupyter_text>Input the data into the dataframe<jupyter_code>data = pd.read_csv(r'C:\Users\kamat\Downloads\seattle\listings.csv')
data.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 3818 entries, 0 to 3817
Data columns (total 92 columns):
id                                  3818 non-null int64
listing_url                         3818 non-null object
scrape_id                           3818 non-null int64
last_scraped                        3818 non-null object
name                                3818 non-null object
summary                             3641 non-null object
space                               3249 non-null object
description                         3818 non-null object
experiences_offered                 3818 non-null object
neighborhood_overview               2786 non-null object
notes                               2212 non-null object
transit                             2884 non-null object
thumbnail_url                       3498 non-null object
medium_url                          3498 non-null object
picture_url                         3818 non-null object
xl_picture_url                      3498[...]<jupyter_text>check the coulmn is super host and manipulate values as super host or regular host<jupyter_code>data['host_is_superhost'].replace('t','SuperHost',inplace = True) 
data['host_is_superhost'].replace('f','Regular Host',inplace =True)
data['price'] = data['price'].str.replace('$','')
data['price'] = data['price'].str.replace(',','').astype('float64')
data.head()<jupyter_output><empty_output><jupyter_text>The data needs to be cleansed, the $ signs are removed from all prices, and the % symbols are replaced by the actual decimal value<jupyter_code>data['weekly_price'] = data['weekly_price'].str.replace('$','')
data['weekly_price'] = data['weekly_price'].str.replace(',','').astype('float64')

data['monthly_price'] = data['monthly_price'].str.replace('$','')
data['monthly_price'] = data['monthly_price'].str.replace(',','').astype('float64')
data['cleaning_fee'] = data['cleaning_fee'].str.replace('$','')
data['cleaning_fee'] = data['cleaning_fee'].str.replace(',','').astype('float64')
data['host_response_rate'] = data['host_response_rate'].str.replace('%','').astype('float64')/100
data['host_acceptance_rate'] = data['host_acceptance_rate'].str.replace('%','').astype('float64')/100
data.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 3818 entries, 0 to 3817
Data columns (total 92 columns):
id                                  3818 non-null int64
listing_url                         3818 non-null object
scrape_id                           3818 non-null int64
last_scraped                        3818 non-null object
name                                3818 non-null object
summary                             3641 non-null object
space                               3249 non-null object
description                         3818 non-null object
experiences_offered                 3818 non-null object
neighborhood_overview               2786 non-null object
notes                               2212 non-null object
transit                             2884 non-null object
thumbnail_url                       3498 non-null object
medium_url                          3498 non-null object
picture_url                         3818 non-null object
xl_picture_url                      3498[...]<jupyter_text>Getting all the superhost data<jupyter_code>super_data1 = data[['host_is_superhost', 'host_total_listings_count', 'accommodates', 'bathrooms', 'bedrooms', 'beds',
        'price', 'cleaning_fee', 'guests_included',
       'minimum_nights', 'maximum_nights','weekly_price', 'monthly_price', 'availability_365']]
sns.heatmap(super_data1.corr(method='kendall'))<jupyter_output><empty_output><jupyter_text>Getting the summary of data<jupyter_code>super_data1.groupby('host_is_superhost',axis =0).mean()
host_table = pd.DataFrame(data= super_data1.groupby('host_is_superhost',axis =0).mean())

host_table.loc['Delta'] = host_table.loc['Regular Host'] - host_table.loc['SuperHost']

host_table.drop(['accommodates', 'guests_included', 'minimum_nights', 'maximum_nights'], axis = 1, inplace = True)
host_table.head()
host_table['host_total_listings_count'].plot(kind ='bar')<jupyter_output><empty_output><jupyter_text>Number of hosts super hosts and delta<jupyter_code>host_table[['price', 'cleaning_fee']].plot(kind ='bar')

super_data1.groupby(['bedrooms','host_is_superhost'],axis =0).mean()

super_data1.groupby(['bedrooms','host_is_superhost'],axis =0).count()['host_total_listings_count']

super_data2 = data[[ 'host_is_superhost','number_of_reviews', 'review_scores_rating', 'review_scores_accuracy',
       'review_scores_cleanliness', 'review_scores_checkin',
       'review_scores_communication', 'review_scores_location',
       'review_scores_value',
       'reviews_per_month']]
super_data2.groupby('host_is_superhost',axis =0).mean()

review_table = pd.DataFrame(data = super_data2.groupby('host_is_superhost',axis =0).mean())

#review_table.drop(['review_scores_checkin', 'review_scores_value','review_scores_location' ,'review_scores_checkin', 'review_scores_accuracy'], axis =1)

review_table.head()
super_data2.groupby(['host_is_superhost','review_scores_rating'],axis =0).mean()
review_table = pd.DataFrame(data=super_data2.groupby(['host_is_superhost','review_scores_rating'],axis =0).mean())

reg_host_ratings = pd.DataFrame(data =list(review_table.index.get_level_values(1)[:42]), columns =['Regular Host Ratings'])
super_host_ratings =pd.DataFrame(data =list(review_table.index.get_level_values(1)[42:]), columns =['SuperHost Ratings'])
                        
#print(reg_host_ratings)
#print(super_host_ratings)

reg_host_number = pd.DataFrame(data =list(review_table['number_of_reviews'][:42]), columns =['Number of Reviews'])
super_host_number = pd.DataFrame(data= list(review_table['number_of_reviews'][42:]),columns =['Number of Reviews'])
review_table.index
reg_table = pd.concat([reg_host_ratings, reg_host_number], axis =1)

super_table = pd.concat([super_host_ratings, super_host_number], axis =1)

print(super_table)
#print(reg_table)

reg_host_ratings.hist()
super_host_ratings.hist()
super_data3 = data[['host_response_time', 'host_response_rate', 
                    'host_is_superhost','cancellation_policy','instant_bookable', 'host_acceptance_rate']]
super_data3 = pd.DataFrame(data=super_data3)

super_data3.head()

super_data3.info()

super_data3.dropna(subset=['host_acceptance_rate'], inplace=True)

super_data3.info()

super_data3['host_is_superhost'].value_counts()

super_data3['cancellation_policy'].value_counts()
response_speed = pd.DataFrame(data = super_data3.groupby(['host_response_time', 'host_is_superhost'],axis =0).count())
response_speed['host_response_rate']

response_speed['host_response_rate'].plot(kind='bar')

cancel_policy = pd.DataFrame(data = super_data3.groupby(['cancellation_policy', 'host_is_superhost'],axis =0).count())
# Cancel policy counts

cancel_policy['host_response_rate']
cancel_policy['host_response_rate'].plot(kind ='bar')

instant_book = pd.DataFrame(data = super_data3.groupby(['instant_bookable', 'host_is_superhost'],axis =0).count())
instant_book['host_response_rate']
super_data3[:5]

super_data3[['host_is_superhost','host_response_rate','host_acceptance_rate']].groupby(['host_is_superhost'], axis =0).mean()
drop = ['id', 'listing_url', 'scrape_id', 'last_scraped', 'name', 'summary',
       'space', 'description', 'experiences_offered', 'neighborhood_overview',
       'notes', 'transit', 'thumbnail_url', 'medium_url', 'picture_url',
       'xl_picture_url', 'host_id', 'host_url', 'host_name', 'host_since',
       'host_location', 'host_about','host_thumbnail_url', 'host_picture_url', 'host_neighbourhood',
       'street', 'neighbourhood', 'neighbourhood_cleansed',
       'neighbourhood_group_cleansed', 'city', 'state', 'zipcode', 'market',
       'smart_location', 'country_code', 'country', 'latitude', 'longitude',
       'amenities', 'square_feet', 'calendar_last_scraped', 'number_of_reviews',
       'first_review', 'last_review', 'review_scores_rating',
       'review_scores_accuracy', 'review_scores_cleanliness',
       'review_scores_checkin', 'review_scores_communication',
       'review_scores_location', 'review_scores_value', 'requires_license',
       'license', 'jurisdiction_names', 'reviews_per_month']
model_data = data.drop(labels=drop, axis =1)
model_data.info()
model_data['security_deposit'] = model_data['security_deposit'].str.replace('$', '')
model_data['security_deposit'] = model_data['security_deposit'].str.replace(',', '').astype('float64')

model_data['extra_people'] = model_data['extra_people'].str.replace('$', '')
model_data['extra_people'] = model_data['extra_people'].str.replace(',', '').astype('float64')
model_data.info()
model_data.dropna(subset =['bedrooms'], axis =0, inplace = True)

model_data.fillna(value =0, inplace=True)

model_data.drop(1297, inplace =True)
model_data.drop(1419, inplace =True)

model_data.info()
Y = model_data['host_is_superhost']

Y = Y.str.replace('Regular Host','0')
Y = Y.str.replace('SuperHost','1')
Y = Y.astype('float64')


X = pd.get_dummies(model_data.drop(labels=['host_is_superhost'], axis =1))
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X,Y,test_size=0.15, random_state=1)

from sklearn.linear_model import LogisticRegression

model = LogisticRegression()

model.fit(X_train, y_train)
model.score(X_test, y_test)
a = model.coef_.ravel()
b = X_train.columns

c = pd.DataFrame({'feature': b, 'coef': a})

c.sort_values(by = 'coef', ascending =False)[:25].plot(x='feature', y='coef', kind='bar')
features = c.sort_values(by = 'coef', ascending =False)[:12]

from IPython.display import HTML

HTML(features.to_html(index=False))
from sklearn.ensemble import RandomForestRegressor

model_forest = RandomForestRegressor(max_depth=20, random_state=0)
model_forest.fit(X_train, y_train)

print(model_forest.score(X_test, y_test))

model_forest_importances = model_forest.feature_importances_
model_forest_result = pd.DataFrame({'feature': X_train.columns, 'importance': model_forest_importances})
model_forest_result.sort_values(by='importance',ascending=False)[:10].plot(x='feature', y='importance', kind='bar')
X_train.columns
r=model_forest.predict(X_test)

from sklearn.svm import SVC
svm=SVC(kernel="linear",C=0.025,random_state=101)
svm.fit(X_train, y_train)
c=svm.score(X_test,y_test)
c
from sklearn.neighbors import KNeighborsClassifier
neigh = KNeighborsClassifier(n_neighbors=5)
neigh.fit(X_train,y_train)
neigh.score(X_test,y_test)
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
clf = RandomForestClassifier(n_estimators=10, max_depth=None,
...     min_samples_split=2, random_state=0)
scores = cross_val_score(clf, X_train, y_train, cv=5)
scores.mean()
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier(max_depth=None, min_samples_split=2,
    random_state=0)
scores = cross_val_score(clf, X_train, y_train, cv=5)
scores.mean()
from sklearn.ensemble import AdaBoostClassifier
model_ad = AdaBoostClassifier()
model_ad.fit(X_train,y_train)
model_ad.score(X_test,y_test)
from sklearn.ensemble import GradientBoostingClassifier
model_GB = GradientBoostingClassifier(n_estimators=1000)
model_GB.fit(X_train,y_train)
model_GB.score(X_test,y_test)
X=["Logistic Regression","Random Forest Regressor","Support Vector Classifier","KNeighbours classifier","Random Forest Classifier","Deciosn Tree","Ada Boost","Gradient Boost"]
len(X)
Y=[0.7902,0.2695,0.7972,0.7779,0.8202,0.7655,0.8181,0.8251]
len(Y)
plt.bar(Y,X)

import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt

objects = ("Logistic Regression","Random Forest Regressor","Support Vector Classifier","KNeighbours classifier","Random Forest Classifier","Deciosn Tree","Ada Boost","Gradient Boost")
y_pos = np.arange(len(objects))
performance = Y

plt.barh(y_pos, performance, align='center', alpha=0.5)
plt.yticks(y_pos, objects)
plt.xlabel('Score')
plt.title('Algorithms used')

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13818952171433227, 'fraction_numerical': 0.02656237268801434, 'mean_word_length': 5.079247152055473, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '596183', 'license': 'MIT', 'n_tokens_mistral': 4327, 'n_tokens_neox': 4058, 'n_words': 675, 'path': 'Host Analysis/Host Super Host Analysis.ipynb', 'repo_name': 'thevarunjain/airbnb-recommendation-system', 'size': '12273'}