Skip to content

Instantly share code, notes, and snippets.

View christfan868's full-sized avatar
💭
Changing the world, one line at a time...

christfan868

💭
Changing the world, one line at a time...
View GitHub Profile
@christfan868
christfan868 / fbprophet_quickstart.py
Last active May 5, 2017 21:48
Getting up and running with Facebook's Prophet library
# Create a new Prophet Object
prophet = Prophet(holidays=holidays,
growth='logistic',
seasonality_prior_scale=seasonality_prior_scale,
holidays_prior_scale=holidays_prior_scale)
# Training the model on the dataset
prophet.fit(trnDF)
# Create DataFrame of future dates
@christfan868
christfan868 / array_iteration_thoughts.md
Created April 20, 2017 16:35 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@christfan868
christfan868 / retention_profile.py
Created April 14, 2017 23:42
Creating a profile of the staff that have stayed on.
# What does the profile of someone who is likely to stay look like?
stay_df = df[df['left'] == 0]
# apply to multiple fns to multiple cols
retention_profile = pd.DataFrame(columns=[list(df)]) # Create a DataFrame with the same column names as the main DataFrame.
retention_profile = retention_profile.drop('left', 1) # Drop the 'left' column
# Populate the retention profile....
retention_profile = retention_profile.append({'satisfaction_level': stay_df['satisfaction_level'].mean(),
'last_evaluation': stay_df['last_evaluation'].mean(),
@christfan868
christfan868 / attrition_model.py
Created April 14, 2017 16:26
Staff Attrition Prediction Model
# 2. Define Model.
model = Sequential()
model.add(Dense(12, input_dim=9, init='normal', activation='relu'))
model.add(Dense(9, init='normal', activation='relu'))
model.add(Dense(6, init='normal', activation='relu'))
model.add(Dense(3, init='normal', activation='relu'))
model.add(Dense(1, init='normal', activation='sigmoid'))
# 3. Compile Model.
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
@christfan868
christfan868 / pg-pong.py
Created January 11, 2017 08:47 — forked from karpathy/pg-pong.py
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@christfan868
christfan868 / nltk-intro.py
Created April 12, 2016 16:44 — forked from alexbowe/nltk-intro.py
Demonstration of extracting key phrases with NLTK in Python
import nltk
text = """The Buddha, the Godhead, resides quite as comfortably in the circuits of a digital
computer or the gears of a cycle transmission as he does at the top of a mountain
or in the petals of a flower. To think otherwise is to demean the Buddha...which is
to demean oneself."""
# Used when tokenizing words
sentence_re = r'''(?x) # set flag to allow verbose regexps
([A-Z])(\.[A-Z])+\.? # abbreviations, e.g. U.S.A.