Skip to content

Instantly share code, notes, and snippets.

View toniesteves's full-sized avatar

Toni Esteves toniesteves

View GitHub Profile
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
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.
@toniesteves
toniesteves / knn_impute.py
Created May 17, 2020 19:30 — forked from YohanObadia/knn_impute.py
Imputation of missing values with knn.
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):
def double_list_values(my_list, idx):
my_list[idx] = my_list[idx] * 2
def double_and_copy_list_values(items):
new_list = []
for item in items:
new_list.append(item * 2)
return new_list
import time
items = ['coffee'] * 10;
lot_of_items = ['coffee'] * 100000
def find_coffee(items):
start = time.time()
for item in items:
if(item == 'coffe'):
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)
import time
lot_of_items = ['coffee'] * 100000
def find_coffee(items):
start = time.time()
for item in items:
if(item == 'coffe'):
print('Found Coffee')
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
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)))