Skip to content

Instantly share code, notes, and snippets.

View sgodfrey66's full-sized avatar

Stephen Godfrey sgodfrey66

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# Simulate game
n_sims = 10_000
game_record = []
for i in range(n_sims):
# Simulate two dice rolls
rolls = np.random.randint(1,7,2)
# Sum the two dice
sum = rolls.sum()
# Import libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
# Pick a seed for the random number generator
np.random.seed(101)
# Imports
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
from sklearn.datasets import load_boston
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import cross_val_score
# Run the model evaluator function to find the best models
# with between 1 and 13 features selecting from the features list
model_df = model_evaluator(X, y, features, 1, len(features))
# Rearrange columns in the data frame
model_df = model_df[['features', 'model', 'no_features', 'intercept', 'coeff', 'R2', 'CV_R2']]
# Sort the resulting data frame to see the best feature sets
model_df.sort_values(by = 'CV_R2', ascending = False).head()
@sgodfrey66
sgodfrey66 / modeling_pipeline.py
Created May 30, 2020 16:05
A TensorFlow Modeling Pipeline using TensorFlow Datasets and TensorBoard
# Run through the pipeline for each test defined above in tests
# If you don't want to wait for processing to complete, you can shorten the
# the test details list
for test in tests:
# 1. Read the inputs from the test details dictionary
dataset_name=test['dataset_name']
shuffle_size=test['shuffle_size']
batch_size=test['batch_size']
target_height=test['target_height']
# Load a dataset
tensorflow_datasets.load
# Iterate through a dataset
tensorflow.data.Dataset.__iter__()
# Shuffle a dataset
tensorflow.data.Dataset.shuffle()
# Batch a dataset
tensorflow.data.Dataset.batch()
# Map a function to Dataset elements
tensorflow.data.Dataset.map()
class VGG16Test(tf.keras.models.Sequential):
"""Construct a Sequential model using transfer learning with
VGG16 as the base.
This class uses some transfer learning and follows the work of Dr. Sivarama Krishnan Rajaraman, et al in
using 'pre-trained convolutional neural networks' to detect malaria infections in thin blood smear samples;
specifically, the pretrained VGG16 model.
As is the case with SequentialTest, we're building a Sequential model in which the first layer is a part of
the VGG16 model. Therefore, we can follow the same approach in which this class inherits from the
# Create a TensorBoard log directory for input images
init_time=dt.datetime.now(tz.timezone('US/Pacific')).strftime("%b%d_%H:%M")
images_logs='input_images'
image_log='{}'.format(os.path.join(logs_dir,images_logs))
# Create a TensorBoard log directory for training and evaluation data
model_log='{}_{}'.format(os.path.join(logs_dir,model_name),init_time)
# Create a TensorBoard log directory for the confusion matrix
cm_log='{}_{}/conf_matrix'.format(os.path.join(logs_dir,model_name),init_time)
# Create a TensorBoard writer for sample images
image_writer=tf.summary.create_file_writer(logdir=image_log)
# Generate an image grid in a format that can be used by TensorBoard
rnd_imgs=image_funcs.create_TB_image_grid(dataset=ds,
no_log_images=no_log_images,
log_images_split=log_images_split)
# Add it to the TensorBoard logs
with image_writer.as_default():
tf.summary.image(name=rnd_imgs[0], data=rnd_imgs[2],