Testing for Manifold

import sys; sys.version.split()[0]
0.2s
Python
'3.7.5'
pip install xgboost
pip install --upgrade pandas
11.9s
Bash in Python
listings.csv
import pandas as pd
listings = pd.read_csv(
listings.csv
)
listings.head()
0.4s
Python
idnamehost_idhost_nameneighbourhood_groupneighbourhoodlatitudelongituderoom_typepriceminimum_nightsnumber_of_reviewslast_reviewreviews_per_monthcalculated_host_listings_countavailability_365
02818Quiet Garden View Room & Super Fast WiFi3159DanielOostelijk Havengebied - Indische Buurt52.365754.94142Private room5932772019-11-212.09137
120168Studio with private bathroom in the centre 159484AlexanderCentrum-Oost52.365094.89354Private room10013212020-02-072.652134
225428Lovely apt in City Centre (w.lift) near Jordaan56142JoanCentrum-West52.372974.88339Entire home/apt1251452020-02-090.22129
327886Romantic, stylish B&B houseboat in canal district97647FlipCentrum-West52.3876099999999954.8918800000000005Private room15522132020-02-102.161163
428871Comfortable double room124245EdwinCentrum-West52.367194.8909199999999995Private room7523232020-02-102.83114
5 items
y = listings['price']
print(y[0:10])
0.4s
Python
X = listings.drop(columns=['id', 'host_id', 'name', 'host_name', 'last_review', 'price', 'neighbourhood_group', 'neighbourhood', 'availability_365'])
#X['neighbourhood'] = X['neighbourhood'].astype('category')
#X['room_type'] = X['room_type'].astype('category')
X['room_type'] = X['room_type'].replace('Shared room', 0).replace('Hotel room', 1).replace('Private room', 2).replace('Entire home/apt', 3)
X['room_type'] = X['room_type'].astype('int64')
print(X.head())
0.4s
Python
print(X.isnull().sum())
0.4s
Python
X = X.fillna(0)
0.1s
Python
from sklearn.linear_model import BayesianRidge, LinearRegression
from sklearn.ensemble import RandomForestRegressor
0.2s
Python
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5)
0.2s
Python
model = LinearRegression()
model.fit(X_train, y_train)
0.1s
Python
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)
y_predict = model.predict(X_test)
print(y_predict)
0.4s
Python
from sklearn.metrics import explained_variance_score, r2_score
print(explained_variance_score(y_test, y_predict))
print(r2_score(y_test, y_predict))
0.5s
Python

Downloads

X_test
1.1s
Python
y_test
0.8s
Python
pd.DataFrame(y_predict)
1.0s
Python
Runtimes (1)