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 sklearn.linear_model import SGDRegressor | |
>>> from sklearn.datasets import make_regression | |
>>> import numpy as np | |
>>> import pandas as pd | |
>>> ### Load original data | |
>>> original_data = pd.read_csv('sample.csv') | |
>>> print(f'Shape of original data {original_data.shape:.f02}') | |
Shape of original data (100000, 21) |
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
### Concatenate string using '+' operation | |
def add_string_with_plus(iters): | |
s = "" | |
for i in range(iters): | |
s += "abc" | |
assert len(s) == 3*iters | |
### Concatenate strings using join() function | |
def add_string_with_join(iters): | |
l = [] |
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 numpy as np | |
import pandas as pd | |
import objgraph | |
### class without __slots__ | |
class PointWithDict(): | |
def __init__(self, iters): | |
self.iters = iters | |
def convert(self): | |
s = ["xyz"]*self.iters |
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 numpy as np | |
import itertools | |
import sys | |
def append_matrix_with_itertools(X, Y): | |
""" Loop matrix using itertools.product() | |
""" | |
MTX = np.zeros((X, Y)) |
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 tracemalloc | |
>>> import numpy as np | |
>>> def create_array(x, y): | |
>>> x = x**2 | |
>>> y = y**3 | |
>>> return np.ones((x, y, 1024, 3), dtype=np.uint8) | |
>>> tracemalloc.start() | |
>>> ### Run application |
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 numpy as np | |
>>> import sys | |
>>> import objgraph | |
>>> import psutil | |
>>> import pandas as pd | |
>>> ob = np.ones((1024, 1024, 1024, 3), dtype=np.uint8) | |
### Check object 'ob' size |
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 | |
>>> my_generator_list = (i for i in range(100000)) | |
>>> print(f"My generator is {sys.getsizeof(my_generator_list)} bytes") | |
My generator is 128 bytes | |
>>> timeit(my_generator_list) | |
10000000 loops, best of 5: 32 ns per loop | |
>>> my_list = [i for i in range(100000)] | |
>>> print(f"My list is {sys.getsizeof(my_list)} bytes") |
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 data_optimize(df, object_option=False): | |
"""Reduce the size of the input dataframe | |
Parameters | |
---------- | |
df: pd.DataFrame | |
input DataFrame | |
object_option : bool, default=False | |
if true, try to convert object to category |
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
## Example of code annotation for a function | |
def your_function(X): | |
""" Explanation of what the function does | |
Parameters | |
---------- | |
X: dtype | |
explanation of X | |
y: dtype |
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
## Example of the main code pipeline in .py format | |
import sys, os | |
import pandas as pd | |
import numpy as np | |
from your_classes.ClassOne import load_funtion, preprocess_function, training_function, save_result_function | |
import your_classes.PATH | |
def main(): |
NewerOlder