In [32]:
import pandas as pd #work with data as tables
import numpy as np #use number matrices
import matplotlib.pyplot as plt
import tensorflow as tf

In [33]:
# step 1
dataframe = pd.read_csv('data.csv')

In [34]:
dataframe.head()

dataframe = dataframe[0:10]
dataframe


Out[34]:
index area bathrooms price sq_price
0 0 2104.0 3.0 399900.0 190.066540
1 1 1600.0 3.0 329900.0 206.187500
2 2 2400.0 3.0 369000.0 153.750000
3 3 1416.0 2.0 232000.0 163.841808
4 4 3000.0 4.0 539900.0 179.966667
5 5 1985.0 4.0 299900.0 151.083123
6 6 1534.0 3.0 314900.0 205.280313
7 7 1427.0 3.0 198999.0 139.452698
8 8 1380.0 3.0 212000.0 153.623188
9 9 1494.0 3.0 242500.0 162.315930

In [35]:
dataframe = dataframe.drop(['index', 'price','sq_price'], axis=1)

In [36]:
dataframe.head()


Out[36]:
area bathrooms
0 2104.0 3.0
1 1600.0 3.0
2 2400.0 3.0
3 1416.0 2.0
4 3000.0 4.0

In [41]:
# step 2
# 1 is good buy and 0 is bad buy
dataframe.loc[:, ('y1')] = [1, 1, 1, 0, 0, 1, 0, 1, 1,1]
dataframe.loc[:, ('y2')] = dataframe['y1'] == 0
dataframe.loc[:, ('y2')] = dataframe['y2'].astype(int)
dataframe


Out[41]:
area bathrooms y1 y2
0 2104.0 3.0 1 0
1 1600.0 3.0 1 0
2 2400.0 3.0 1 0
3 1416.0 2.0 0 1
4 3000.0 4.0 0 1
5 1985.0 4.0 1 0
6 1534.0 3.0 0 1
7 1427.0 3.0 1 0
8 1380.0 3.0 1 0
9 1494.0 3.0 1 0

In [43]:
# step 3 - prepare data for tensorflow (tensors)
# tensors are a generic version of vectors and matrices
#vector is a list of list of numbers (1D tensor)
#matrix is a list of list numbers (2D Tensor)
#list of list of list of numbers (3D tensor)
#......
#convert features to input tensor
inputX = dataframe.loc[:, ['area', 'bathrooms']].as_matrix()
#convert labels to input tensors
inputY = dataframe.loc[:, ['y1', 'y2']].as_matrix()

In [57]:
#step 4 - write out our hyperparneters
learning_rate = 0.000001
training_epochs = 2000
display_step = 50
n_samples = inputY.size


Out[57]:
20

In [55]:
#step 5 - Create our computation graph/neural network
x = tf.placeholder(tf.float32, [None, 2]) 
W = tf.Variable(tf.zeros([2, 2]))           
b = tf.Variable(tf.zeros([2]))   
y_values = tf.add(tf.matmul(x, W), b)       
y = tf.nn.softmax(y_values)
y_ = tf.placeholder(tf.float32, [None,2])

In [56]:
#step  6 - perform training
# Cost function: Mean squared error
cost = tf.reduce_sum(tf.pow(y_ - y, 2))/(2*n_samples)
# Gradient descent
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)

In [ ]: