import numpy as np
import matplotlib.pyplot as plt
from pylab import plot, show, xlabel, ylabel
def feature_normalize(X):
'''
Returns a normalized version of X where
the mean value of each feature is 0 and the standard deviation
is 1. This is often a good preprocessing step to do when
working with learning algorithms.
'''
mean_r = []
std_r = []
X_norm = X
n_c = X.shape[1] # no of columns -> no of features
for i in range(n_c):
m = np.mean(X[:, i])
s = np.std(X[:, i])
mean_r.append(m)
std_r.append(s)
X_norm[:, i] = (X_norm[:, i] - m) / s
return X_norm, mean_r, std_r
features = np.loadtxt('ex4x.txt', delimiter=',')
X_norm, mean_r, std_r = feature_normalize(features)
#Plot the data
'''
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
n = 100
for c, m, zl, zh in [('r', 'o', -50, -25)]:
xs = features[:, 0]
ys = features[:, 1]
zs = features[:, 2]
ax.scatter(xs, ys, zs, c=c, marker=m)
ax.set_xlabel('Size of the House')
ax.set_ylabel('Number of Bedrooms')
ax.set_zlabel('Price of the House')
plt.show()
'''