This file contains hidden or 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 matplotlib.pyplot as plt | |
| import numpy as np | |
| import pandas as pd | |
| from sklearn.ensemble import RandomForestRegressor | |
| from sklearn.linear_model import LinearRegression, Lasso, Ridge | |
| from sklearn.neighbors import KNeighborsRegressor | |
| from sklearn.neural_network import MLPRegressor | |
| from sklearn.tree import DecisionTreeRegressor | |
| from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score, cross_val_predict, KFold | |
| import xgboost as xgb |
This file contains hidden or 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 plot(self,run_results,with_alarm = True, positions = None): | |
| """ | |
| Plot the results of given by the run | |
| Parameters | |
| ---------- | |
| run_results : dict | |
| results given by the 'run' method | |
| with_alarm : bool | |
| (default = True) If True, alarms are plotted. |
This file contains hidden or 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 numpy as np | |
| import pandas as pd | |
| from collections import defaultdict | |
| from scipy.stats import hmean | |
| from scipy.spatial.distance import cdist | |
| from scipy import stats | |
| import numbers | |
| def weighted_hamming(data): |
This file contains hidden or 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 double_list_values(my_list, idx): | |
| my_list[idx] = my_list[idx] * 2 |
This file contains hidden or 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 double_and_copy_list_values(items): | |
| new_list = [] | |
| for item in items: | |
| new_list.append(item * 2) | |
| return new_list |
This file contains hidden or 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 time | |
| items = ['coffee'] * 10; | |
| lot_of_items = ['coffee'] * 100000 | |
| def find_coffee(items): | |
| start = time.time() | |
| for item in items: | |
| if(item == 'coffe'): |
This file contains hidden or 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
| authors = ['Andrew Ng', 'Josh Stamer', 'Kent Beck', | |
| 'Martin Fowler', 'Erick Evans', 'Erich Gamma']; | |
| def first_two_authors(authors): | |
| print(authors[0]) # O(1) | |
| print(authors[1]) # O(1) | |
| first_two_authors(authors) # O(2) | |
This file contains hidden or 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 time | |
| lot_of_items = ['coffee'] * 100000 | |
| def find_coffee(items): | |
| start = time.time() | |
| for item in items: | |
| if(item == 'coffe'): | |
| print('Found Coffee') |
This file contains hidden or 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
| items = [1, 2, 3, 4, 5, 6 , 7, 8, 9, 10] | |
| def binary_search(alist, item): | |
| first = 0 | |
| last = len(alist)-1 | |
| found = False | |
| while first <= last and not found: | |
| midpoint = (first + last)//2 |
This file contains hidden or 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 itertools import chain, combinations | |
| authors = ['Andrew Ng', 'François Chollet', 'Josh Stamer', 'Kent Beck', 'Erick Evans', 'Soumith Chintala']; | |
| def subsets(iterable): | |
| s = list(iterable) | |
| return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) | |
| print(list(subsets(authors))) |