Skip to content

Instantly share code, notes, and snippets.

View morganmcg1's full-sized avatar
💭
Trying to ML

Morgan McGuire morganmcg1

💭
Trying to ML
View GitHub Profile
@morganmcg1
morganmcg1 / pyspark_normalize.py
Last active July 10, 2023 03:45
PySpark - Normalize (Standardize) train and test dataframes: [ (x - mean) / std_dev ]
# Based on the solution here: https://stackoverflow.com/questions/44580644/subtract-mean-from-pyspark-dataframe
# Function to normalise (standardise) PySpark dataframes
def standardize_train_test_data(train_df, test_df, columns):
'''
Add normalised columns to the input dataframe.
formula = [(X - mean) / std_dev]
Inputs : training dataframe, list of column name strings to be normalised
Returns : dataframe with new normalised columns, averages and std deviation dataframes
'''
@morganmcg1
morganmcg1 / full_width.py
Created November 22, 2017 09:26
Full width Jupyter Notebooks, insert in first jupyter cell
%%html
<style>
.output_wrapper, .output {
height:auto !important;
max-width:9000px;
}
.output_scroll {
box-shadow:none !important;
webkit-box-shadow:none !important;
}
@morganmcg1
morganmcg1 / plot_confusion_matrix.py
Created November 29, 2017 17:57
Plot a confusion, with the option to normalise the values
def plot_confusion_matrix(cm,
classes,
normalize,
title):
'''
PARAMETERS:
- cm: SKL.METRICS confustion matrix
- Classes: the labels used in the classification
- normalize=False : (True will normalise the values, can be useful for large sample with few outliers)
- title : should be set to: 'Confusion matrix'
@morganmcg1
morganmcg1 / plot_correct_quadrant_classification.py
Created November 29, 2017 17:58
For multi class problems decide how the model performed in a binary situation
# for multi class problems decide whether the model was correct going long or short
def correct_quadrant_classifications(cls_labels, cm):
#Find nuumber of correct classifications
correct_clf = 0
if len(cls_labels) % 2 == 0:
for i in range(0, len(cls_labels)):
correct_clf = correct_clf + cm[i][i]
# calculate the rate of correct predictions
correct_clf_rate = correct_clf/cm.sum()
#print('\n{:.0f} out of {:.0f} predictions were correct'.format(correct_clf, cm.sum()))
@morganmcg1
morganmcg1 / open_awscli.txt
Created December 4, 2017 18:02
Running aws from cygwin
1. type cd C: in Cygwin:
2. cd: Program Files/Anaconda3/Scripts
3. python aws
@morganmcg1
morganmcg1 / install-opencv-cuda.sh
Created December 24, 2017 11:55 — forked from pvilas/install-opencv-cuda.sh
Installing OpenCV CUDA and python3 (Tested on AWS p2.xlarge and Deep Learning Ubuntu AMI 22_Aug_2017)
echo "First, you must manually donwload CUDA8 from https://developer.nvidia.com/cuda-downloads"
echo "Ideas taken from https://github.com/BVLC/caffe/wiki/OpenCV-3.2-Installation-Guide-on-Ubuntu-16.04 and http://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/"
echo "Installing Nvidia drivers"
# Start clean
sudo apt purge nvidia-*
# Add the PPA
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
sudo apt-get install nvidia-367
@morganmcg1
morganmcg1 / tictactoe.py
Last active December 27, 2019 21:43
Two player python game of Tic Tac Toe to play in the terminal
#!/usr/bin/env python
"""
TIC-TAC-TOE
A basic two-player game of tic-tac-toe
Written by Morgan McGuire
www.github.com/morganmcg1
"""
@morganmcg1
morganmcg1 / fasthugs_demo_buggy.ipynb
Created April 5, 2020 20:33
fasthugs : get_preds in ClassificationInterpretation.from_learner(learn) not working
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add to your ~/.gitconfig
[alias]
lg = !"git lg1"
lg1 = !"git lg1-specific --all"
lg2 = !"git lg2-specific --all"
lg3 = !"git lg3-specific --all"
lg1-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)'
lg2-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'

Note to self to update a PR:

1. git checkout <branch-of-fork>
2. git add <filename>
3. git commit -m "updated the feature"

4. git push origin <branch-of-fork>
OR 
4. git push fork <branch-of-fork>