image_output_1.png
from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plot

import numpy as np

import pandas as pd

import sklearn as sk

def print_summary(opt_reg_object):
    params = opt_reg_object.best_estimator_.get_params()
    score = -opt_reg_object.best_score_
    return

hp = pd.read_csv('../input/london-house-prices/hpdemo.csv')
hp

scaler = SS()
scaler.fit(hp[['east', 'north', 'fl_area']])
hp_sc = scaler.transform(hp[['east', 'north', 'fl_area']])

mod1 = NN(n_neighbors=6, weights='uniform', p=2)
price = hp['price'] / 1000.0
mod1.fit(hp_sc, price)

mae = sk.metrics.make_scorer(sk.metrics.mean_absolute_error, greater_is_better=False)
mod_list = sk.model_selection.GridSearchCV(estimator=NN(), scoring=mae, param_grid={'n_neighbors': range(1, 35), 'weights': ['uniform', 'distance'], 'p': [1, 2]})
mod_list.fit(hp[['east', 'north', 'fl_area']], price)

east_mesh, north_mesh = np.meshgrid(np.linspace(505000, 555800, 100), np.linspace(158400, 199900, 100))
fl_mesh = np.zeros_like(east_mesh)
fl_mesh2 = np.zeros_like(east_mesh)
fl_mesh3 = np.zeros_like(east_mesh)
fl_mesh[:, :] = np.mean(hp['fl_area'])
fl_mesh2[:, :] = 75
fl_mesh3[:, :] = 125
regressor_df = np.array([np.ravel(east_mesh), np.ravel(north_mesh), np.ravel(fl_mesh)]).T
regressor_df2 = np.array([np.ravel(east_mesh), np.ravel(north_mesh), np.ravel(fl_mesh2)]).T
regressor_df3 = np.array([np.ravel(east_mesh), np.ravel(north_mesh), np.ravel(fl_mesh3)]).T

hp_pred = mod_list.predict(regressor_df)
hp_pred2 = mod_list.predict(regressor_df2)
hp_pred3 = mod_list.predict(regressor_df3)
hp_mesh = hp_pred.reshape(east_mesh.shape)
hp_mesh2 = hp_pred2.reshape(east_mesh.shape)
hp_mesh3 = hp_pred3.reshape(east_mesh.shape)

#Plot1 
fig = plot.figure()
ax = Axes3D(fig)
ax.plot_surface(east_mesh, north_mesh, hp_mesh, rstride=1, cstride=1, cmap='YlOrBr',lw=0.01)
plot.title('London House Prices')
ax.set_xlabel('Easting')
ax.set_ylabel('Northing')
ax.set_zlabel('Price at Mean Floor Area')
plot.show()

#Plot2 
fig = plot.figure()
ax = Axes3D(fig)
ax.plot_surface(east_mesh, north_mesh, hp_mesh2, rstride=1, cstride=1, cmap='YlOrBr',lw=0.01)
plot.title('London House Prices')
ax.set_xlabel('Easting')
ax.set_ylabel('Northing')
ax.set_zlabel('Price at 75m Floor Area')
plot.show()

fig = plot.figure()
ax = Axes3D(fig)
ax.plot_surface(east_mesh, north_mesh, hp_mesh3, rstride=1, cstride=1, cmap='YlOrBr', lw=0.01)
plot.title('London House Prices')
ax.set_xlabel('Easting')
ax.set_ylabel('Northing')
ax.set_zlabel('Price at 125m Floor Area')
plot.show()