Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢
Working away...

Shay Palachy shaypal5

🐢
Working away...
View GitHub Profile
@shaypal5
shaypal5 / pdp_post_adv2.py
Last active Aug 1, 2022
An example for an advanced initialization of a complex pdpipe pipeline for processing pandas dataframes. 🐼🚿
View pdp_post_adv2.py
>>> mp = MyPipelineAndModel(
savings_max_val=101,
drop_gender=False,
standardize=True,
ohencode_country=True,
savings_bin_val=1,
pca_threshold=25,
fit_intercept=True)
>>> mp
<PdPipeline -> LogisticRegression>
@shaypal5
shaypal5 / pdp_post_adv.py
Last active Aug 5, 2022
An example for an advanced initialization of a complex pdpipe pipeline for processing pandas dataframes. 🐼🚿
View pdp_post_adv.py
from typing import Optional
import pdpipe as pdp
from pdpipe import df
from sklearn.linear_model import LogisticRegression
from pdpipe.skintegrate import PdPipelineAndSklearnEstimator
class MyPipelineAndModel(PdPipelineAndSklearnEstimator):
def __init__(
self,
@shaypal5
shaypal5 / pdpipe_2nd_look.py
Last active Jul 9, 2022
Another minimal example of some pdpipe features.
View pdpipe_2nd_look.py
>>> df = pd.DataFrame(
... [[23, 'Jo', 45], [19, 'Bo', 72], [15, 'Di', 12], [5, 'Jo', 0]],
... columns=['age', 'name', 'salary'])
>>> df
age name salary
0 23 Jo 45
1 19 Bo 72
2 15 Di 12
3 5 Jo 0
>>> pipeline = pdp.DropDuplicates('name').Bin({'salary': [0, 20, 50]}) \
@shaypal5
shaypal5 / funk_mf_recommender.py
Created Jul 1, 2022
A naive implementation of Funk's MF for collaborative filtering (commonly and wrongly called SVD for collaborative filtering). Might contain mistakes (let me know).
View funk_mf_recommender.py
from typing import Tuple, Optional
import numpy as np
import pandas as pd
def train_val_split(
training_df: pd.DataFrame,
val_ratio: float,
) -> Tuple[pd.DataFrame, pd.DataFrame]:
"""Splits the input training dataset into train/val set.
@shaypal5
shaypal5 / pdpipe_first_look.py
Last active Jun 27, 2022
pdpipe first look
View pdpipe_first_look.py
>>> df = pd.DataFrame(
data=[[4, 165, 'USA'], [2, 180, 'UK'], [2, 170, 'Greece']],
index=['Dana', 'Jane', 'Nick'],
columns=['Medals', 'Height', 'Born']
)
>>> df
Medals Height Born
Dana 4 165 USA
Jane 2 180 UK
Nick 2 170 Greece
@shaypal5
shaypal5 / deepchecks-phishing-grad-boost-model-eval.py
Created Jan 16, 2022
Deepchecks Phishing URLs Example: Gradient Boosting Model Evaluation
View deepchecks-phishing-grad-boost-model-eval.py
from sklearn.ensemble import GradientBoostingClassifier
model = GradientBoostingClassifier(n_estimators=250, random_state=SEED, max_depth=20, subsample=0.8 , loss='exponential')
model.fit(train_X, train_y)
msuite.run(model=model, train_dataset=ds_train, test_dataset=ds_test)
@shaypal5
shaypal5 / deepchecks-phishing-random-forest-model-eval.py
Created Jan 16, 2022
Deepchecks Phishing URLs Example: Random Forest Model Evaluation
View deepchecks-phishing-random-forest-model-eval.py
from sklearn.tree import DecisionTreeClassifier
model = DecisionTreeClassifier(criterion='entropy', splitter='random', random_state=SEED)
model.fit(train_X, train_y)
msuite.run(model=model, train_dataset=ds_train, test_dataset=ds_test)
@shaypal5
shaypal5 / deepchecks-phishing-log-reg-model-eval.py
Last active Jan 16, 2022
Deepchecks Phishing URLs Example: Log Reg Model Evaluation
View deepchecks-phishing-log-reg-model-eval.py
from deepchecks.suites import model_evaluation
msuite = model_evaluation()
msuite.run(model=logreg, train_dataset=ds_train, test_dataset=ds_test)
@shaypal5
shaypal5 / deepchecks-phishing-first-train-test-val.py
Created Jan 16, 2022
Deepchecks Phishing URLs Example: First Train Test Validation Suite
View deepchecks-phishing-first-train-test-val.py
from deepchecks.suites import train_test_validation
vsuite = train_test_validation()
ds_train = deepchecks.Dataset(df=train_X, label=train_y, set_datetime_from_dataframe_index=True, cat_features=[])
ds_test = deepchecks.Dataset(df=test_X, label=test_y, set_datetime_from_dataframe_index=True, cat_features=[])
vsuite.run(model=logreg, train_dataset=ds_train, test_dataset=ds_test)
@shaypal5
shaypal5 / deepchecks-phishing-preprocessing.py
Last active Jan 16, 2022
Deepchecks Phishing URLs Example: Preprocessing
View deepchecks-phishing-preprocessing.py
from deepchecks.datasets.classification.phishing import get_url_preprocessor
pipeline = get_url_preprocessor()
train_df = pipeline.fit_transform(raw_train_df)
train_X = train_df.drop('target', axis=1)
train_y = train_df['target']
test_df = pipeline.transform(raw_test_df)
test_X = test_df.drop('target', axis=1)
test_y = test_df['target']