Back to Modin

Demonstrating Tensorflow Modin Interoperability

examples/jupyter/integrations/tensorflow.ipynb

0.37.11.5 KB
Original Source

Demonstrating Tensorflow Modin Interoperability

All the examples in this section are taken/ adapted from https://www.tensorflow.org/tutorials/load_data/pandas_dataframe

python
import tensorflow as tf
import modin.pandas as pd
import pandas
python
SHUFFLE_BUFFER = 500
BATCH_SIZE = 2

csv_file = tf.keras.utils.get_file('heart.csv', 'https://storage.googleapis.com/download.tensorflow.org/data/heart.csv')

modin_df = pd.read_csv(csv_file)
modin_df.head()
python
target = modin_df.pop('target')
python
numeric_feature_names = ['age', 'thalach', 'trestbps',  'chol', 'oldpeak']
numeric_features = modin_df[numeric_feature_names]
numeric_features.head()
python
tf.convert_to_tensor(numeric_features)
python
normalizer = tf.keras.layers.Normalization(axis=-1)
normalizer.adapt(numeric_features)

Replicating statsmodels workflow with pandas

python
SHUFFLE_BUFFER = 500
BATCH_SIZE = 2

csv_file = tf.keras.utils.get_file('heart.csv', 'https://storage.googleapis.com/download.tensorflow.org/data/heart.csv')

pandas_df = pandas.read_csv(csv_file)
pandas_df.head()
python
target = pandas_df.pop('target')
python
numeric_feature_names = ['age', 'thalach', 'trestbps',  'chol', 'oldpeak']
numeric_features = pandas_df[numeric_feature_names]
numeric_features.head()
python
tf.convert_to_tensor(numeric_features)
python
normalizer = tf.keras.layers.Normalization(axis=-1)
normalizer.adapt(numeric_features)