This file contains 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
class BloodPressureDataPoint(object): | |
def __init__(self, systole, diastole, hr): | |
self.systole = systole | |
self.diastole = diastole | |
self.hr = hr | |
print("finished initializing") |
This file contains 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
""" 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): |
This file contains 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
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]: | |
continue | |
else: |
This file contains 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
def get_nodes_parent(tree, node_to_evaluate): | |
for i, row in enumerate(tree): | |
if row[node_to_evaluate] == 1: | |
return i | |
else: | |
return None | |
This file contains 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
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: |
This file contains 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
if obs_mean < null_mean: | |
pval = 2 * (null_vals < obs_mean).mean() | |
else: | |
pval = 2 * (null_vals > obs_mean).mean() | |
pval |
This file contains 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
from pandas import DataFrame, Series | |
a = [1, 2, 3, 4] | |
b = a.append(5) | |
print(a) | |
# [1, 2, 3, 4, 5] | |
print(b) | |
# None |
This file contains 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
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) |
This file contains 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
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Applications/PyCharmOld.app/Contents/helpers/pydev/pydevd.py --multiproc --qt-support --client 127.0.0.1 --port 54837 --file /Users/piyushgupta/projects/udacityintroML/final_project/poi_id.py | |
pydev debugger: process 6180 is connecting | |
Connected to pydev debugger (build 143.2371) | |
/Library/Python/2.7/site-packages/sklearn/cross_validation.py:41: 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 |
This file contains 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 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 main.py "2018-1-25" | |
sys.argv would be [main.py', '2018-1-25'] |
NewerOlder