This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NCLASSES = 2 | |
| HEIGHT = 224 | |
| WIDTH = 224 | |
| NUM_CHANNELS = 3 | |
| BATCH_SIZE = 32 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| !pip install tensorflow-gpu==2.0.0-beta0 | |
| import tensorflow as tf | |
| from tensorflow.keras import layers, models, optimizers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use an official Python runtime as a parent image | |
| FROM python:2.7-slim | |
| # Set the working directory to /app | |
| WORKDIR /app | |
| # Copy the current directory contents into the container at /app | |
| COPY . /app | |
| # Install any needed packages specified in requirements.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #standardSQL | |
| SELECT | |
| * | |
| FROM | |
| ML.PREDICT(MODEL `bqml_tutorial.sample_model`, ( | |
| SELECT | |
| IFNULL(device.operatingSystem, "") AS os, | |
| device.isMobile AS is_mobile, | |
| IFNULL(totals.pageviews, 0) AS pageviews, | |
| IFNULL(geoNetwork.country, "") AS country |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| * | |
| FROM | |
| ML.CONFUSION_MATRIX(MODEL `bqml_tutorial.sample_model`, | |
| ( | |
| SELECT | |
| IF(totals.transactions IS NULL, 0, 1) AS label, | |
| IFNULL(device.operatingSystem, "") AS os, | |
| device.isMobile AS is_mobile, | |
| IFNULL(geoNetwork.country, "") AS country, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| * | |
| FROM | |
| ML.ROC_CURVE(MODEL `bqml_tutorial.sample_model`, | |
| ( | |
| SELECT | |
| IF(totals.transactions IS NULL, 0, 1) AS label, | |
| IFNULL(device.operatingSystem, "") AS os, | |
| device.isMobile AS is_mobile, | |
| IFNULL(geoNetwork.country, "") AS country, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| * | |
| FROM | |
| ML.EVALUATE(MODEL `bqml_tutorial.sample_model`, | |
| ( | |
| SELECT | |
| IF(totals.transactions IS NULL, 0, 1) AS label, | |
| IFNULL(device.operatingSystem, "") AS os, | |
| device.isMobile AS is_mobile, | |
| IFNULL(geoNetwork.country, "") AS country, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #standardSQL | |
| CREATE MODEL `bqml_tutorial.sample_model` | |
| OPTIONS(model_type='logistic_reg') AS | |
| SELECT | |
| IF(totals.transactions IS NULL, 0, 1) AS label, | |
| IFNULL(device.operatingSystem, "") AS os, | |
| device.isMobile AS is_mobile, | |
| IFNULL(geoNetwork.country, "") AS country, | |
| IFNULL(totals.pageviews, 0) AS pageviews | |
| FROM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AUTOTUNE = tf.data.experimental.AUTOTUNE | |
| path_ds = tf.data.Dataset.from_tensor_slices(train_file_list) | |
| image_ds = path_ds.map(load_and_preprocess_image, num_parallel_calls=AUTOTUNE) | |
| label_ds = tf.data.Dataset.from_tensor_slices(tf.cast(train_label_list, tf.int64)) | |
| image_label_ds = tf.data.Dataset.zip((image_ds, label_ds)) | |
| ds = image_label_ds.shuffle(buffer_size=1000 * BATCH_SIZE) | |
| ds = ds.repeat() | |
| ds = ds.batch(BATCH_SIZE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| from tensorflow import keras | |
| model = keras.models.Sequential([ | |
| keras.layers.Dense(4, activation=tf.nn.relu, input_shape=(4,), kernel_regularizer=keras.regularizers.l1_l2(l1=0.1, l2=0.01)), | |
| keras.layers.Dense(4, activation=tf.nn.relu, kernel_regularizer=keras.regularizers.l1_l2(l1=0.1, l2=0.01)), | |
| keras.layers.Dense(1, activation=tf.nn.sigmoid) | |
| ]) | |
| model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) |