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
[tool.black] | |
line-length = 109 | |
target-version = ['py37'] | |
[tool.isort] | |
profile = "black" |
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
repos: | |
- repo: https://github.com/pre-commit/pre-commit-hooks | |
rev: v2.3.0 | |
hooks: | |
- id: check-yaml | |
- id: end-of-file-fixer | |
- id: trailing-whitespace | |
- repo: https://github.com/psf/black | |
rev: 21.12b0 | |
hooks: |
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 argparse | |
import os | |
from train import train_cnn | |
# let's define some default hyperparameter values | |
PROJECT_NAME = "fashion_mnist" | |
BATCH_SIZE = 32 | |
DROPOUT = 0.2 | |
EPOCHS = 20 |
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
""" | |
Defines a simple CNN model on the fashion mnist dataset. | |
""" | |
from keras.preprocessing.image import ImageDataGenerator | |
from keras.datasets import fashion_mnist | |
from tensorflow.keras.models import Sequential | |
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dropout, Dense, Flatten | |
from tensorflow.keras.optimizers import Adam | |
from keras.utils import np_utils |
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
study = optuna.create_study(direction="minimize") | |
study.optimize(objective, n_trials=500) | |
print(f"Optimized RMSE: {study.best_value:.4f}") | |
print("Best params:") | |
for key, value in study.best_params.items(): | |
print(f"\t{key}: {value}") |
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 objective(n_trials): | |
params = { | |
"n_estimators": n_trials.suggest_int("n_estimators", 100, 2000, step=100), | |
"learning_rate": n_trials.suggest_float("learning_rate", 1e-4, 0.3, log=True), | |
"max_depth": n_trials.suggest_int("max_depth", 3, 15), | |
"n_iter_no_change": 50, | |
} | |
dtrain = xgb.DMatrix(data = X_train, label = y_train) | |
dval = xgb.DMatrix(data = X_test, label = y_val) |
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
from sklearn.model_selection import train_test_split | |
X = df.drop(columns=['median_house_value']) | |
y = df.median_house_value | |
# split the data | |
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=0) | |
X_train.shape, X_val.shape, y_train.shape, y_val.shape | |
# make a new regressor model |
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
# Do grid search | |
from sklearn.model_selection import GridSearchCV | |
rf_classifier = RandomForestClassifier(random_state=0) | |
rf_model_pipeline = Pipeline(steps=[ | |
('preprocessing', columns_transformer), | |
('rf_model', rf_classifier), | |
]) |
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
# MODEL Pipeline | |
from sklearn.ensemble import RandomForestClassifier | |
from sklearn.metrics import confusion_matrix, accuracy_score | |
import matplotlib.pyplot as plt | |
# random forest classifier | |
rf_classifier = RandomForestClassifier(n_estimators = 11, criterion='entropy', random_state=0) | |
rf_model_pipeline = Pipeline(steps=[ |
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
# COLUMN PIPELINE | |
from sklearn.impute import SimpleImputer | |
from sklearn.preprocessing import MinMaxScaler | |
from sklearn.pipeline import Pipeline | |
from sklearn.compose import ColumnTransformer | |
› | |
col_transformation_pipeline = Pipeline(steps=[ | |
('impute', SimpleImputer(strategy='mean')), |
NewerOlder