Skip to content

Instantly share code, notes, and snippets.

@kmedved
kmedved / contemplative-llms.txt
Created January 6, 2025 21:03 — forked from Maharshi-Pandya/contemplative-llms.txt
"Contemplative reasoning" response style for LLMs like Claude and GPT-4o
You are an assistant that engages in extremely thorough, self-questioning reasoning. Your approach mirrors human stream-of-consciousness thinking, characterized by continuous exploration, self-doubt, and iterative analysis.
## Core Principles
1. EXPLORATION OVER CONCLUSION
- Never rush to conclusions
- Keep exploring until a solution emerges naturally from the evidence
- If uncertain, continue reasoning indefinitely
- Question every assumption and inference
@kmedved
kmedved / NumbaDecisionTreeRegressor.py
Last active December 13, 2024 13:26
Faster DecisionTreeRegressor for use with Ngboost
import numpy as np
from numba import njit, prange
from sklearn.base import BaseEstimator, RegressorMixin
@njit(inline='always')
def weighted_variance_from_sums(sum_w, sum_wy, sum_wy_sq):
# Weighted variance: var_w = (sum_wy_sq / sum_w) - (sum_wy / sum_w)**2
if sum_w <= 1e-14:
return 0.0
mean_w = sum_wy / sum_w
def fit_catboost_model(df,
features,
label_col,
sample_weight_col = None,
raw_model = CatBoostRegressor(),
cv_splitter = GroupShuffleSplit(n_splits=2, test_size = 0.3),
group_id_col = None,
verbose = False,
split_type = None):
"""
def fit_mrmr(df,
features,
label_col,
sample_weight_col = None,
group_id_col = 'nba_id',
max_features = 50,
n_repeats = 1,
n_splits = 5,
n_jobs = 1,
early_stopping_rounds = None):
def shorten_features_boruta(df,
features,
label_col,
sample_weight_col = None,
n_trials = 100,
gpu = False,
n_jobs = 8,
classification_fl = False,
sample_fl = True,
base_model = None):
def shorten_features_catboost(df,
features,
label_col,
n_estimators = 200,
sample_weight_col = None,
model = None,
group_id = None,
steps = 6,
gpu = False,
n_jobs = 8,
@kmedved
kmedved / weighted_chaterjee.py
Created April 29, 2022 16:07 — forked from bbstats/weighted_chaterjee.py
weighted_chaterjee.py
from scipy.stats import rankdata
import numpy as np
def weighted_chaterjee_correlation(x, y, sample_weight=None):
"""x and y must be 1d, probably"""
n = x.size
rk_x = rankdata(x, method="average")
rk_y = rankdata(y, method="average")
@kmedved
kmedved / hebo_patch.py
Created January 4, 2022 21:30 — forked from bbstats/hebo_patch.py
Simple patch of HEBO to support sample weights (via fit_params argument)
# requirements to pip install:
#
# numpy
# pandas
# sklearn
# HEBO
#
#
import numpy as np
import pandas as pd
@kmedved
kmedved / skboost.py
Created July 22, 2021 23:13
Skboost
from threadpoolctl import threadpool_limits
from sklearn.experimental import enable_hist_gradient_boosting
from sklearn.ensemble import HistGradientBoostingRegressor
class SkBoost(HistGradientBoostingRegressor):
def __init__(
self,
loss="least_squares",
learning_rate=0.1,
max_iter=100,
@kmedved
kmedved / scrape_pbpstats
Created July 20, 2021 12:37
PBPstats API Endpoints
def get_pbpstats(nba_game_id, stats_type = 'box'):
# Convert the game ID
nba_game_id = str(nba_game_id)
if len(nba_game_id) < 10:
nba_game_id = '00' + nba_game_id
# Figure out the right URL