09.05.2023 Views

pdfcoffee

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3

Where YY̅ and AA̅ are the average price and area respectively. Let us try this on some

simple sample data:

1. We import the necessary modules. It is a simple example so we'll be using

only NumPy, pandas, and Matplotlib:

import tensorflow as tf

import numpy as np

import matplotlib.pyplot as plt

import pandas as pd

2. Next, we generate random data with a linear relationship. To make it more

real we also add a random noise element. You can see the two variables (the

cause: area, and the effect: price) follow a positive linear dependence:

#Generate a random data

np.random.seed(0)

area = 2.5 * np.random.randn(100) + 25

price = 25 * area + 5 + np.random.randint(20,50, size = len(area))

data = np.array([area, price])

data = pd.DataFrame(data = data.T, columns=['area','price'])

plt.scatter(data['area'], data['price'])

plt.show()

[ 91 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!