Skip to content

Instantly share code, notes, and snippets.

View data-hound's full-sized avatar

Anshuman Sabath data-hound

View GitHub Profile
@data-hound
data-hound / MIMO4sklearn_CV.py
Last active January 22, 2021 17:55
Scikeras Tutorial - 5: Wrapping the MIMO Estimator and giving a CV run
# Helper Method to get data into shape to pass to GridSearchClassifier
def get_sciki_xy(X,y):
X_sciki = np.column_stack([X.reshape((y.shape[0], np.prod(X.shape[1:]))), y])
y_sciki = np.column_stack([y,X.reshape((y.shape[0], np.prod(X.shape[1:])))])
return X_sciki,y_sciki
def do_cross_val():
(x_train_, y_train_), (x_test_, y_test_) = load_mnist() #load the dataset
@data-hound
data-hound / Input_Reshaper.py
Last active January 22, 2021 17:55
Scikeras Tutorial - 4: Input transformer and MIMOEstimator
def input_reshaper(X):
return [X[:,:-10].reshape(X.shape[0],28,28,1), X[:,-10:]]
@data-hound
data-hound / MOTransformer.py
Last active January 22, 2021 17:54
Scikeras Tutorial - 3: Multi Output Transformer for CapsNet
from typing import List
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.preprocessing import LabelEncoder, FunctionTransformer, OneHotEncoder
class MultiOutputTransformer(BaseEstimator, TransformerMixin):
def fit(self, y):
# Separate the two different 'y's into two arrays
@data-hound
data-hound / DataTransformers_for_classifiers.py
Last active January 22, 2021 17:53
Scikeras Tutorial-2: DataTransformers Template
from sklearn.base import BaseEstimator, TransformerMixin
from scikeras.wrappers import KerasClassifier
### Multi-Output Classifier
class MultiOutputTransformer(BaseEstimator, TransformerMixin):
#define your transformer
class MultiOutputClassifier(KerasClassifier):
@data-hound
data-hound / Pre-existing wrappers.py
Last active January 18, 2021 20:18
Scikeras Tutorial -1
import numpy as np
from sklearn.datasets import make_classification
from tensorflow import keras
from tensorflow.keras.wrappers.scikit_learn import KerasClassifier
# Make a dummy dataset
X, y = make_classification(1000, 20, n_informative=10, random_state=0)
X = X.astype(np.float32)
y = y.astype(np.int64)