Skip to content

Instantly share code, notes, and snippets.

View nktnlx's full-sized avatar
💭
Python, SQL, A/B-tests, Tableau, Statistics, etc.

Alex Nikitin nktnlx

💭
Python, SQL, A/B-tests, Tableau, Statistics, etc.
View GitHub Profile
@nktnlx
nktnlx / quick_sort.py
Created April 29, 2023 05:22
quick sort implementation
def quick_sort(lst):
# Base case
if len(lst) <= 1:
return lst
# Choose pivot element (last element in array)
pivot = lst[-1]
# Initialize two lists to store elements less than or greater than pivot
left, right = [], []
@nktnlx
nktnlx / merge_sort.py
Created April 29, 2023 05:17
merge sort implementation
def merge_sort(lst):
# Base case: if the array has 0 or 1 element, it is already sorted
if len(lst) <= 1:
return lst
# Recursive case: split the array into two halves, sort each half, and merge them
mid = len(lst) // 2
left_half = lst[:mid]
right_half = lst[mid:]
@nktnlx
nktnlx / bubble_sort.py
Created April 29, 2023 05:11
bubble sort implementation
def bubble_sort(lst):
# Get the length of the input list
cnt = len(lst)
# Iterate over the list until all elements are sorted
while cnt > 0:
# Iterate over each element in the list
for i in range(1, len(lst)):
# Compare the current element with the previous element
if lst[i - 1] > lst[i]:
# If the previous element is larger, swap the elements
@nktnlx
nktnlx / list_graph_representation.py
Created April 15, 2023 05:47
ways to represent a graph with a list data structure
# edge list graph representation example
edge_list_graph = [[0, 1], [1, 2],
[1, 3], [2, 3]]
# adjacency list graph representation example
adjacency_list_graph = [[1], [0, 2, 3],
[1, 3], [1, 2]]
# here we use index in a list as an id number of verices in a graph
@nktnlx
nktnlx / graph_representation.py
Created April 15, 2023 05:41
graph representation with networkx code snippet
import networkx as nx
import matplotlib.pyplot as plt
# Create an empty graph
G = nx.Graph()
# Add edges to the graph
G.add_edge(1, 2) # edge between node 1 and node 2
G.add_edge(1, 3) # edge between node 1 and node 3
@nktnlx
nktnlx / titanic_random_forest.py
Last active March 25, 2023 07:08
chatgpt random forest titanic problem solution
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder, StandardScaler
from sklearn.impute import SimpleImputer
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import Pipeline
from sklearn.compose import ColumnTransformer
from sklearn.metrics import accuracy_score
@nktnlx
nktnlx / titanic_log_reg.py
Created March 25, 2023 06:44
titanic logistic regression solution by chatgpt (changed nothing in the code)
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import re
import seaborn as sns
train_df = pd.read_csv('~/titanic_chatgpt/train.csv')
test_df = pd.read_csv('~/titanic_chatgpt/test.csv')
# handle missing values
@nktnlx
nktnlx / ab_paired_stratification.py
Created March 18, 2023 06:51
paired stratification splitting technique
import random
# Define the data
users = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
values = [0, 0, 11, 11, 10, 10, 20, 20, 30, 30]
# Define the splitter
splitter = {}
@nktnlx
nktnlx / ab_stratification.py
Created March 18, 2023 06:11
stratification splitting technique
import random
from collections import defaultdict
# Define our users and their features
users = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
feature = ['iOS', 'iOS', 'iOS', 'iOS',
'iOS', 'iOS', 'iOS', 'iOS',
'Android', 'Android']
@nktnlx
nktnlx / ab_randomization.py
Created March 18, 2023 05:43
randomization splitting technique
import random
# Set the proportion of visitors to assign to each group
control_proportion = 0.5
variation_proportion = 0.5
# Create a list of visitors
visitors = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]