Skip to content

Instantly share code, notes, and snippets.

View mertbozkir's full-sized avatar
🔥
Delayed Gratification!

Mert Bozkir mertbozkir

🔥
Delayed Gratification!
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mertbozkir
mertbozkir / fit_ml_algo.py
Last active May 31, 2021 21:40
Function that run ML Algorithms easily
# Function that runs the requested algorithm and returns the accuracy metrics
def fit_ml_algo(algo, X_train, y_train, cv):
# One Pass
model = algo.fit(X_train, y_train)
acc = round(model.score(X_train, y_train) * 100, 2)
# Cross Validation
train_pred = model_selection.cross_val_predict(algo,
X_train,
@mertbozkir
mertbozkir / Codeland_Username_Validation.py
Last active June 3, 2021 16:41
Codeland Username Validation Solution
def CodelandUsernameValidation(strParam):
if (4<len(strParam)<25) or (strParam[0] != str) or strParam[-1] == "_":
return False
return True
# keep this function call here
print(CodelandUsernameValidation(input()))
"""
@mertbozkir
mertbozkir / maxArea_of_Cake.py
Last active June 4, 2021 15:40
Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
import numpy as np
class Solution:
def areaEdge(self, h_w: int, Cuts: List[int]) -> int:
Cuts.insert(len(Cuts), h_w)
temp_list = Cuts[:-1]
temp_list.insert(0,0)
Cuts.sort()
temp_list.sort()
@mertbozkir
mertbozkir / Reverse_Integer.py
Last active June 5, 2021 21:10
String approach to reverse integer problem
class Solution:
def reverse(self, x: int) -> int:
ex = str(x)
if ex[0] == "-":
ex2 = ex[1:]
print(ex2[::-1])
if not((-2)**31 < int(ex2[::-1]) < 2**31 - 1):
return 0
return ex[0] + str(int(ex2[::-1]))
else:
@mertbozkir
mertbozkir / binary_search.py
Created January 2, 2022 16:15
Binary Search algorithm O(log n) runtime complexity
def search(nums, target) -> int:
high = len(nums) - 1
low, mid = 0, 0
while low <= high:
mid = (high + low)// 2
if nums[mid] < target:
low = mid + 1
@mertbozkir
mertbozkir / LinearRegression.ipynb
Last active May 12, 2022 08:21
Simple Linear Regression with Gradient Descent from Scratch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mertbozkir
mertbozkir / val_curve_params.py
Last active May 14, 2022 12:58
Learning Curves Plotting function
def val_curve_params(model, X, y, param_name, param_range, scoring = 'roc_auc', cv = 10):
train_score, test_score = validation_curve(
model, X = X, y = y, param_name = param_name, param_range = param_range, scoring = scoring, cv = cv)
mean_train_score = np.mean(train_score, axis = 1)
mean_test_score = np.mean(test_score, axis = 1)
plt.plot(param_range, mean_train_score,
label = 'Training Score', color = 'b')
plt.plot(param_range, mean_test_score,
@mertbozkir
mertbozkir / plot_importance.py
Last active May 14, 2022 12:58
Plotting feature importances for machine learning model.
def plot_importance(model, features, num = len(X), save = False):
feature_imp = pd.DataFrame({'Value': model.feature_importances_, 'Feature': features.columns})
plt.figure(figsize = (10, 10))
sns.set(font_scale = 1)
sns.barplot(x = 'Value', y = 'Feature',
data = feature_imp.sort_values(by = 'Value', ascending = False)[0:num])
plt.title('Features')
plt.tight_layout()
plt.show()
if save:
@mertbozkir
mertbozkir / cypher.zsh-theme
Last active June 22, 2024 21:44
Updated Cypher theme with virtualenv
# Based on evan's prompt
# Shows the exit status of the last command if non-zero
# Uses "#" instead of "»" when running with elevated privileges
# local venv_prompt='$(virtualenv_prompt_info)'
# PROMPT='%{${fg_bold[blue]}%}$(virtualenv_prompt_info)'
PROMPT="%m %{${fg_bold[red]}%}::%{${fg[green]}%} %3~%{${reset_color}%} $(virtualenv_prompt_info)%(0?. . ${fg[red]}%? )%{${fg[blue]}%}» "
# PROMPT="%{${fg_bold[white]}%} %m %{${fg_bold[red]}%}:: %{${fg[green]}%}%3~%(0?. . %{${fg[red]}%}%? )%{${fg[blue]}%}$(virtualenv_prompt_info)» %{${reset_color}%}"
ZSH_THEME_VIRTUALENV_PREFIX=""
ZSH_THEME_VIRTUALENV_SUFFIX=""