Apache Spark Deep Learning Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

This section walks through the steps to visualize all of the predicted points in a graph.

  1. Compute the minimum and maximum points of the graph  using the following script:
x_min = min(data_array[:,0])-0.1
x_max = max(data_array[:,0])+0.1
y_min = min(data_array[:,1])-0.1
y_max = max(data_array[:,1])+0.1
increment= 0.05

print(x_min, x_max, y_min, y_max)
  1. Generate x and y values in increments of 0.05 units and then create an array called xy_data, as seen in the following script:
x_data= np.arange(x_min, x_max, increment)
y_data= np.arange(y_min, y_max, increment)
xy_data = [[x_all, y_all] for x_all in x_data for y_all in y_data]
  1. Finally, a similar script to that used earlier in the chapter is used to generate a gender score and populate a graph, as seen in the following script:
for i in range(len(xy_data)):
data = (xy_data[i])
height = data[0]
weight = data[1]
z_new = height*w1 + weight*w2 + b
predictedGender_new=sigmoid(z_new)
# print(height, weight, predictedGender_new)
ax = plt.scatter(height[predictedGender_new<=0.5],
weight[predictedGender_new<=0.5],
marker = 'o', c= 'r', label = 'Female')
bx = plt.scatter(height[predictedGender_new > 0.5],
weight[predictedGender_new>0.5],
marker = 'o', c= 'b', label = 'Male')
# plot values, title, legend, x and y axis
plt.title('Weight vs Height by Gender')
plt.xlabel('Height (in)')
plt.ylabel('Weight (lbs)')
plt.legend(handles=[ax,bx])