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 typing import Tuple, List | |
| class MinMaxScaler: | |
| def __init__(self, values: Tuple) -> List: | |
| self.values = values | |
| self.min_val = min(values) | |
| self.max_val = max(values) | |
| self.max_min_diff = self.max_val - self.min_val | |
| def min_max_scale(self, x: Tuple): |
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 typing import Dict, Iterable, List, KeysView, ItemsView, ValuesView | |
| import matplotlib.pyplot as plt | |
| import pandas as pd | |
| import requests | |
| class Pokemon: | |
| def __init__(self, name: str = None, number: int = None) -> None: | |
| if name and number: |
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 median(vector): | |
| sorted_vector = sorted(vector) | |
| vector_length = len(vector) | |
| middle = vector_length // 2 | |
| if vector_length % 2 != 0: | |
| return sorted_vector[middle] | |
| else: | |
| return (sorted_vector[middle] + sorted_vector[middle - 1]) / 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 functools import partial | |
| def pipe(data, *steps): | |
| for step in steps: | |
| if callable(step): | |
| data = step(data) | |
| elif hasattr(type(step), "__iter__"): | |
| func, *others = step | |
| for arg in others: |
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 sklearn.model_selection import KFold, GridSearchCV | |
| from sklearn.ensemble import RandomForestRegressor | |
| from sklearn.datasets import load_boston | |
| boston = load_boston() | |
| X = boston.data | |
| y = boston.target | |
| # Create kf instance | |
| kf = KFold(n_splits=5, shuffle=True, random_state=42) |
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 sklearn.model_selection import KFold, GridSearchCV | |
| from sklearn.ensemble import RandomForestRegressor | |
| from sklearn.datasets import load_boston | |
| boston = load_boston() | |
| X = boston.data | |
| y = boston.target | |
| # Create kf instance | |
| kf = KFold(n_splits=5, shuffle=True, random_state=42) |
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 pandas as pd | |
| from sklearn.model_selection import KFold, GridSearchCV | |
| from sklearn.ensemble import RandomForestRegressor | |
| from sklearn.datasets import load_boston | |
| boston = load_boston() | |
| X = boston.data | |
| y = boston.target | |
| # Create kf instance |
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 statsmodels.formula.api import ols | |
| from scipy.stats import ttest_ind, mannwhitneyu | |
| def permut_concat(iterable): | |
| """Concatenate iterables of arrays then randomize.""" | |
| return np.random.permutation(np.concatenate(iterable)) | |
| # Make two distributions: a, b |
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 this import s | |
| # Without long strings | |
| def rot13(x): | |
| abc = "".join(map(chr, range(65, 91))) | |
| a_to_m = x in abc[:13] + abc[:13].lower() | |
| n_to_z = x in abc[13:] + abc[13:].lower() | |
| return chr(ord(x) + 13 * (a_to_m or -n_to_z)) |
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 pathlib import Path | |
| from functools import partial | |
| def chaine(data, *funcs, | |
| global_assign=False, | |
| print_results=False, | |
| write_results=False, | |
| **kwargs): | |
| chaine_options = any([global_assign, print_results, write_results]) |
NewerOlder