Let's Get Started With Data Science, World!

Author(s): kozyr@google.com

Reviewer(s): nrh@google.com

It's a beautiful day and we can do all kinds of pretty things. Here are some little examples to get you started.

Print: ...something


In [0]:
print('Hello world!')

Numpy: make some noise!

numpy is the essential package for working with numbers. Simulate some noise and make a straight line.


In [0]:
import numpy as np
n = 20
intercept = -10
slope = 5
noise = 10
error = np.random.normal(0, noise, 20)
x = np.array(range(n))
y = intercept + slope * x + error

print(x)
print(np.round(y, 2))

Pandas: not just for chewing bamboo

pandas is the essential package for working with dataframes. Make a convenient dataframe for using our feature to predict our label.


In [0]:
import pandas as pd
df = pd.DataFrame({'feature': x, 'label': y})
print(df)

Seaborn: pretty plotting

A picture is worth a thousand numbers. seaborn puts some glamour in your plotting style.


In [0]:
import seaborn as sns
%matplotlib inline
sns.regplot(x='feature', y='label', data=df)

In [0]:
%matplotlib inline
sns.distplot(error, axlabel='residuals')

In [0]:
%matplotlib inline
sns.jointplot(x='feature', y='label', data=df)

TensorFlow: built for speed

tensorflow is the essential package for training neural networks efficiently at scale. In order to be efficient at scale, it only runs when it's required to. Let's ask it to greet us...


In [0]:
import tensorflow as tf

c = tf.constant('Hello, world!')

with tf.Session() as sess:

  print sess.run(c)

Finally, let's greet our tensorflow supported devices! Say hello to our CPU, and our GPU if we invited it to the party!


In [0]:
from tensorflow.python.client import device_lib

def get_devices():
  devices = device_lib.list_local_devices()
  return [x.name for x in devices]

print(get_devices())