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 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 = [], [] |
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 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:] | |
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 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 |
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
# 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 |
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 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 |
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 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 |
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 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 |
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 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 = {} |
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 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'] |
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 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] |
NewerOlder