Skip to content

Instantly share code, notes, and snippets.

@Eligijus112
Eligijus112 / factorial.py
Created March 19, 2022 21:09
Factorial of n
def factorial(n: int) -> float:
"""
Given a positive integer, calculate its factorial
"""
if not isinstance(n, int):
raise TypeError('n must be an integer')
if n < 0:
raise ValueError("n must be positive")
@Eligijus112
Eligijus112 / InsertionSort.py
Created March 19, 2022 20:31
Insertion sort algorithm in Python
# Importing the base class
from algorithms.BaseClass import BaseClass
class InsertionSort(BaseClass):
def __init__(
self,
arr: list
):
# Inheriting the base class constructor
@Eligijus112
Eligijus112 / SelectionSort.py
Created March 19, 2022 19:54
Selection sort algorithm in Python
# Importing the base class
from algorithms.BaseClass import BaseClass
class SelectionSort(BaseClass):
def __init__(
self,
arr:list
):
# Inheriting the base class
@Eligijus112
Eligijus112 / BaseClass.py
Created March 18, 2022 06:51
Base class for sorting algorithms
class BaseClass:
def __init__(
self,
arr: list = [float]
):
"""
The base class for all the algorithms to inherit from
"""
# Ensuring the correct type
if type(arr) != list:
@Eligijus112
Eligijus112 / bs_experiment.py
Created March 11, 2022 10:17
Bubble sort experiment
# Maximum number of array length
_max_length = 50
# Defining the amount of expiremnts in each test
_n_experiments = 200
# Iteration results
_iter_results = []
for i in range(_max_length + 1):
@Eligijus112
Eligijus112 / BubbleSort.py
Last active March 18, 2022 06:57
Bubble sort implementation
# Base class
from algorithms.BaseClass import BaseClass
class BubbleSort(BaseClass):
def __init__(self, arr: list):
"""
Object constructor
Arguments
@Eligijus112
Eligijus112 / test_read_data.py
Created March 3, 2022 15:04
A unit test example
# Importing the function to test
from pipeline.modules.read_data import read_json
# Dir traversal
import os
def test_data_reading():
"""
Tests the data reading functionality of the pipeline
"""
@Eligijus112
Eligijus112 / test_pipeline.py
Created March 3, 2022 09:11
End to end test
# Importing the main pipeline function
from pipeline.pipeline import pipeline
# Directory traversal
import os
# Data frame objects
import pandas as pd
# Defining the test
@Eligijus112
Eligijus112 / test_read_clean.py
Last active March 1, 2022 09:52
Integration test
# Main frameworks to test out
from pipeline.modules.read_data import read_json
from pipeline.modules.clean_data import clean_text
# Directory traversals
import os
def test_reading_cleaning():
# Arrange
_path_to_data = os.path.join(
@Eligijus112
Eligijus112 / pipeline.py
Last active March 4, 2022 07:21
CLF creation pipeline
# Importing all the methods for the pipeline
from pipeline.modules.read_data import read_json
from pipeline.modules.clean_data import clean_text
from pipeline.modules.model_input_preparation import create_X_Y, apply_train_test_split
from pipeline.modules.model_fitting import TextCLF
from pipeline.modules.evaluate_model import eval_model
# Directory traversal
import os