import numpy as np import pandas as pd import matplotlib.pyplot as plt %matplotlib inline import seaborn as sns
Tensorflow Practice
Data set loading and visualization
Data Preprocessing/transforming
Modeling using tf.nn (more basic) / tf.keras (advance and convenient API for modeling)
Performance Visualization
Model saving and reuse, reload
1 2 3 4 5 6
import tensorflow as tf import tensorflow.keras as keras # This one-hot convert words to index number rather than binary form from tensorflow.keras.preprocessing.text import one_hot #tf.one_hot import text/ labels into binary 0,1 form without compression from numba import cuda
1 2
# Check if GPU is enabled print(cuda.gpus)
<Managed Device 0>, <Managed Device 1>
Basic Practise
tf.constant contain types of data. Operation like +, -, *, / , should be applied to data with same types only
# The first param in get_file: the name of dataset to save # The second param: url to the dataset trainset_path = keras.utils.get_file('titanic_train.csv', TRAIN_DATA_URL) testset_path = keras.utils.get_file('titanic_test.csv', TEST_DATA_URL) trainset_path, testset_path
Downloading data from https://storage.googleapis.com/tf-datasets/titanic/train.csv
32768/30874 [===============================] - 0s 0us/step
Downloading data from https://storage.googleapis.com/tf-datasets/titanic/eval.csv
16384/13049 [=====================================] - 0s 0us/step
('/home/wenkanw/.keras/datasets/titanic_train.csv',
'/home/wenkanw/.keras/datasets/titanic_test.csv')