Predicting House Prices using a Deep Neural Network: Case with the Boston Dataset

Introduction

Exploratory Data Analysis

sns.heatmap(df.corr(), linewidths=1.5, linecolor='white', cmap='coolwarm', annot=True)
g = sns.PairGrid(df[['Crime Rate', '# of Rooms', 'N.O. Concentration', '% Lower Income']])g.map_upper(plt.scatter, color="m")
g.map_lower(sns.kdeplot, cmap="Set2")
g.map_diag(sns.distplot);

Feature Preparation

df.isnull().sum()

Creating and Training our Neural Network

model.fit(X_train, y_train, epochs=500, callbacks=[early_stop], validation_data=[X_test, y_test], verbose=0)
loss_df = pd.DataFrame(model.history.history)loss_df[['loss', 'val_loss']].plot()plt.xlabel("Number of Epochs")
plt.ylabel("Loss")
plt.title("Training and Validation Loss Over Training Period", pad=12);

Performance Evaluation

arr_predictions = np.array([x[0] for x in predictions])errors = y_test - arr_predictionsfig = plt.figure(figsize=(15, 5))sub1 = fig.add_subplot(121)# Our predictions
plt.scatter(y_test,predictions)
# Perfect predictions
plt.plot(y_test,y_test,'r')
plt.xlabel("Actual")
plt.ylabel("Predicted")
plt.title("Visualizing Residuals with Scatter Plot")
sub1 = fig.add_subplot(122)
sns.distplot(errors)
plt.xlabel("Residuals")
plt.ylabel("Distribution")
plt.title("Visualizing Residuals with Dist Plot");

Feature Importance and Feature Effect

Final Thoughts

Scientist & Mortgage Data Expert