<jupyter_start><jupyter_text><jupyter_code>!pip install sklearn
from __future__ import absolute_import, division, print_function, unicode_literals

!pip install tensorflow==2.0.0-beta1
# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import feature_column
from tensorflow.keras import layers
from sklearn.model_selection import train_test_split

# Helper libraries
import numpy as np
import matplotlib.pyplot as plt

print(tf.__version__)

import pandas as pd
URL = 'https://storage.googleapis.com/applied-dl/heart.csv'

df = pd.read_csv(URL)
df.head()<jupyter_output><empty_output><jupyter_text>Split the data<jupyter_code>train, test = train_test_split(df, test_size=0.2)
train, val = train_test_split(train, test_size=0.2)

len(test)<jupyter_output><empty_output><jupyter_text>pd.Dataframe to tf.Data<jupyter_code>def df_to_dataset(dataframe, shuffle =True, batch_size=32):
  dataframe = dataframe.copy()
  labels = dataframe.pop('target')
  
  ds = tf.data.Dataset.from_tensor_slices((dict(dataframe), labels))
  
  if shuffle :
    ds = ds.shuffle(buffer_size=len(dataframe))
  ds = ds.batch(batch_size)
  
  return ds
batch_size = 5
train_ds = df_to_dataset(train, batch_size=batch_size)
val_ds = df_to_dataset(val, shuffle=False, batch_size=batch_size)
test_ds = df_to_dataset(test, shuffle=False, batch_size=batch_size)
example_batch=next(iter(train_ds))[0]
def demo(feature_column):
  feature_layer = layers.DenseFeatures(feature_column)
  print(feature_layer(example_batch).numpy())
age = feature_column.numeric_column('age')
demo(age)
thal = feature_column.categorical_column_with_vocabulary_list('thal',['fixed','normal','reversible'])

thal_one_hot = feature_column.indicator_column(thal)
demo(thal_one_hot)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10979060554612337, 'fraction_numerical': 0.006791171477079796, 'mean_word_length': 7.84, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '625493', 'license': 'MIT', 'n_tokens_mistral': 639, 'n_tokens_neox': 625, 'n_words': 110, 'path': 'feature_columns.ipynb', 'repo_name': 'abiB27/deeplearning.ai-Assignments', 'size': '1767'}