# Linear regression example - demonstrates the use of placeholder nodes import tensorflow as tf import numpy as np from sklearn.datasets import fetch_california_housing # Fetch data to use in the placeholder nodes housing = fetch_california_housing() m, n = housing.data.shape housing_data_plus_bias = np.c_[np.ones((m, 1)), housing.data] # Set up the computation graph X = tf.placeholder(tf.float32, shape=(None, n+1), name="X") y = tf.placeholder(tf.float32, shape=(None, 1), name="y") XT = tf.transpose(X) theta = tf.matmul(tf.matmul(tf.matrix_inverse(tf.matmul(XT, X)), XT), y) # Run the graph with tf.Session() as sess: theta_val = theta.eval(feed_dict={X:housing_data_plus_bias,y:housing.target.reshape(-1,1)}) print(theta_val)