Skip to content

Instantly share code, notes, and snippets.

Piyush Gupta piyushg91

  • Los Angeles, CA
Block or report user

Report or block piyushg91

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
""" Coding Test: Group all the anagrams into sets
def get_unique_anagram_key(anagram):
anagram = anagram.replace(' ', '') # Get rid of any spaces
split_anagram = sorted(list(anagram))
key = ''.join(split_anagram)
return key
def group_list_by_anagrams(input_list):
def get_edge_order(sorted_edges, all_nodes):
set_trackers = {node: set(node) for node in all_nodes}
edge_order = []
for edge, _ in sorted_edges:
node1, node2 = edge[0], edge[1]
# Case where the nodes already belong to the same set
if set_trackers[node1] == set_trackers[node2]:
def get_nodes_parent(tree, node_to_evaluate):
for i, row in enumerate(tree):
if row[node_to_evaluate] == 1:
return i
return None
View whatevs
def calculate_path_weight(node, seen_nodes, current_weight):
# Case when we've seen all the nodes
if set(seen_nodes) == set(input_graph.keys()):
return current_weight
to_return_path_weight = 10000
for path_node, path_weight in input_graph[node]:
if path_node not in seen_nodes:
new_seen_nodes = seen_nodes + [path_node]
total_path_weight = calculate_path_weight(path_node, new_seen_nodes, current_weight + path_weight)
if total_path_weight < to_return_path_weight:
if obs_mean < null_mean:
pval = 2 * (null_vals < obs_mean).mean()
pval = 2 * (null_vals > obs_mean).mean()
from pandas import DataFrame, Series
a = [1, 2, 3, 4]
b = a.append(5)
# [1, 2, 3, 4, 5]
# None
View bleh
selk = SelectKBest(k=5)
dtc = DecisionTreeClassifier(max_depth=6, random_state=42, min_samples_split=3)
pipline_steps = [
('best_feature', selk),
('decision_tree', dtc)
clf = Pipeline(pipline_steps)
View data
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Applications/ --multiproc --qt-support --client --port 54837 --file /Users/piyushgupta/projects/udacityintroML/final_project/
pydev debugger: process 6180 is connecting
Connected to pydev debugger (build 143.2371)
/Library/Python/2.7/site-packages/sklearn/ DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
total number of data points: 146
total number of people in dataset: 146
total number of poi: 18
total number of not poi: 128
import sys
from datetime import date
import quandl
'''sys.argv is a module that has all the inputs of a command line in a list
so for example if you run
python "2018-1-25"
sys.argv would be [', '2018-1-25']
import requests
import pandas as pd
import matplotlib.pyplot as plt
def get_bls_key():
This method will get the BLS API key that is expected in api-key.txt file. That file is in the .gitignore and
each user should have their own API key
You can’t perform that action at this time.