Skip to content

Instantly share code, notes, and snippets.

View kylegallatin's full-sized avatar

Kyle Gallatin kylegallatin

View GitHub Profile
from sklearn.pipeline import make_pipeline
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
## logistic regression parameter config
parameters = {
"penalty":"l2",
"C":1.0,
"max_iter": 100
import csv
import joblib
import sklearn.pipeline
from datetime import datetime
## helper function to save a model/pipeline
def save_pipeline(pipeline: sklearn.pipeline.Pipeline, ts: datetime = None) -> str:
model_path = f"data/pipeline-{ts}.pkl".replace(" ","-")
joblib.dump(pipeline, model_path)
return model_path
from typing import Iterable, Callable, Dict
class SuperSimpleFeatureStore:
def __init__(self, dataframe: pd.DataFrame):
self.dataframe = dataframe
self.feature_dict = dataframe.set_index("user_id").T.to_dict()
def register_feature(self, name: str, feature_definition: Callable) -> None:
for key in self.feature_dict:
import pandas as pd
from collections import Counter
print("LinkedIn Data Summary", "-"*50, sep = "\n")
connections = pd.read_csv("Connections.csv", parse_dates = ["Connected On"], skiprows=2)["Connected On"]
print("Total connections:", len(connections))
d = Counter(connections.apply(lambda x: x.year))
print("\n".join([f"{v} new connections in {k}" for k,v in d.items()][::-1]), "so far 😉", "\n", "-"*50)
messages = pd.read_csv("messages.csv", parse_dates = ["DATE"])
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ml-app-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: localhost
http:
apiVersion: v1
kind: Service
metadata:
name: ml-app-service
spec:
selector:
app: ml-app
ports:
- protocol: TCP
port: 5000
apiVersion: apps/v1
kind: Deployment
metadata:
name: ml-app-deployment
labels:
app: ml-app
spec:
replicas: 1
selector:
matchLabels:
dash==1.20.0
dash-bootstrap-components==0.12.2
dash-core-components==1.16.0
dash-html-components==1.1.3
dash-renderer==1.9.1
dash-table==4.11.3
matplotlib==3.3.2
numpy==1.19.2
numpydoc==1.1.0
pandas==1.1.3

Kubernetes Practical Intro for Data Scientists

Today we're going to show you how to deploy an application on Kubernetes. You'll only need to Docker Desktop installed locally with Kubernetes enabled.

Testing Our Application with Docker

To deploy an app on Kubernetes, we first need to make sure it works locally with Docker. Use the example fastapi app here: https://github.com/kylegallatin/fast-bad-ml

# clone repo
import threading
import time
import sys
import asyncio
import concurrent.futures
import time
import nest_asyncio
import pyaudio
import wave