Skip to content

Instantly share code, notes, and snippets.

View JonathanLoscalzo's full-sized avatar

Jonathan Loscalzo JonathanLoscalzo

View GitHub Profile
@JonathanLoscalzo
JonathanLoscalzo / demo.py
Created October 29, 2019 15:03 — forked from joelthchao/demo.py
Keras uses TensorBoard Callback with train_on_batch
import numpy as np
import tensorflow as tf
from keras.callbacks import TensorBoard
from keras.layers import Input, Dense
from keras.models import Model
def write_log(callback, names, logs, batch_no):
for name, value in zip(names, logs):
summary = tf.Summary()
@JonathanLoscalzo
JonathanLoscalzo / gridsearch_example.py
Created February 17, 2020 15:10
gridsearch_example for post
params_rf = {
'clf__n_estimators':[
100,
300,
500
],
'clf__min_samples_leaf': [
1,
2,
4
@JonathanLoscalzo
JonathanLoscalzo / evaluate_classifier.py
Created February 17, 2020 15:18
evaluate_classifiers example for post
@utils.timeit
def evaluate_classifier(clf, X, y, scoring='accuracy'):
scores = cross_val_score(clf, X, y, scoring='accuracy', cv=StratifiedKFold(3), verbose=0)
name = type(clf).__name__ if (type(clf).__name__ != 'Pipeline') else type(clf.steps[-1][1]).__name__
print(f'{name} : {scores.mean()} +/- {scores.std()}')
@JonathanLoscalzo
JonathanLoscalzo / get_pipeline_model.py
Last active February 28, 2020 13:27
Pipeline Model
def get_pipeline_model(clf):
return Pipeline([
('preprocess', preprocess_pipeline()),
('clf', clf)
])
@JonathanLoscalzo
JonathanLoscalzo / transformers.py
Created February 28, 2020 13:20
Function Transformers Example
get_numeric_data = FunctionTransformer(lambda df: df[NUMERIC_COLUMNS])
get_text_data = FunctionTransformer(lambda df: df[TEXT_COLUMNS])
get_date_data = FunctionTransformer(lambda df: df[['date_recorded']])
transform_date_data = FunctionTransformer(lambda df: df.assign(
date_recorded_day=df.date_recorded.dt.day,
date_recorded_month=df.date_recorded.dt.month,
date_recorded_year=df.date_recorded.dt.year
).drop('date_recorded', axis=1))
@JonathanLoscalzo
JonathanLoscalzo / preprocess_pipeline.py
Created February 28, 2020 13:24
Feature Union example
def preprocess_pipeline():
return FeatureUnion(
transformer_list = [
('date_features', Pipeline([
('selector', get_date_data),
('transform', transform_date_data)
])),
('numeric_features', Pipeline([
('selector', get_numeric_data),
('imputer', SimpleImputer()),
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JonathanLoscalzo
JonathanLoscalzo / report.md
Created March 13, 2020 15:39
report for post

Metrics for: Test

accuracy: 0.8068054280175492

Classification Report

target precision recall f1-score support
functional 0.90 0.80 0.85 12051
functional needs repair 0.29 0.63 0.40 665
non functional 0.77 0.84 0.80 6886
@JonathanLoscalzo
JonathanLoscalzo / package.json
Created April 13, 2020 22:18
package json examples with pre-hooks and other libs
{
"name": "node-ts-barebones",
"version": "0.0.1",
"description": "Barebones NodeJS setup with TypeScript, Jest, TSLint and Prettier",
"author": "Tiago Pina - <tiagoaspina@gmail.com>",
"license": "MIT",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"format": "prettier --write \"src/**/*.ts\"",
"start": "ts-node -r tsconfig-paths/register src/main.ts",
@JonathanLoscalzo
JonathanLoscalzo / 01-directory-structure.md
Created April 29, 2020 19:31 — forked from tracker1/01-directory-structure.md
Anatomy of a JavaScript/Node project.

Directory structure for JavaScript/Node Projects

While the following structure is not an absolute requirement or enforced by the tools, it is a recommendation based on what the JavaScript and in particular Node community at large have been following by convention.

Beyond a suggested structure, no tooling recommendations, or sub-module structure is outlined here.

Directories

  • lib/ is intended for code that can run as-is
  • src/ is intended for code that needs to be manipulated before it can be used