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 json | |
import openai | |
openai.api_key = "sk-" | |
def classifier(description, labels, label_descriptions): | |
def classify(text): | |
function = { | |
"name": "Classify", | |
"description": description, |
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 os | |
from flask import Flask, session, abort, redirect, request | |
from google_auth_oauthlib.flow import Flow | |
app = Flask(__name__) | |
app.secret_key = os.urandom(24) | |
# Get client secrets file from https://console.cloud.google.com/apis/credentials -> OAuth client ID -> Web application | |
flow = Flow.from_client_secrets_file( |
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 json | |
import openai | |
from inspect import signature, Parameter | |
openai.api_key = "sk-" | |
def func2tool(func): | |
"""Convert a function into OpenAI function calling API format.""" | |
assert func.__doc__, f"Function {func.__name__} must have a docstring." |
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 numpy as np | |
from scipy.ndimage import convolve | |
dim = 10 | |
board = np.zeros((dim, dim), dtype=np.uint8) | |
kernel = np.array([[1,1,1], | |
[1,0,1], | |
[1,1,1]], dtype=np.uint8) | |
def step(board, kernel=kernel): |
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
absl-py==0.12.0 | |
alabaster==0.7.12 | |
albumentations==0.1.12 | |
altair==4.1.0 | |
appdirs==1.4.4 | |
argon2-cffi==20.1.0 | |
arviz==0.11.2 | |
astor==0.8.1 | |
astropy==4.2.1 | |
astunparse==1.6.3 |
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 keras.models import Sequential | |
from keras.layers import LSTM, Dense | |
from sklearn.metrics import mean_squared_error | |
timesteps = window_size-1 | |
n_features = 1 | |
model = Sequential() | |
model.add(LSTM(16, activation='relu', input_shape=(timesteps, n_features), return_sequences=True)) | |
model.add(LSTM(16, activation='relu')) |
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 skimage.util import view_as_windows | |
window_size = 5 | |
timeseries = np.array([1,2,3,4,5,6,7,8,9,10]) | |
trajectory_matrix = view_as_windows(timeseries, window_shape=window_size) |
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 keras.layers import LSTM, Dense, RepeatVector, TimeDistributed | |
from keras.models import Sequential | |
class LSTM_Autoencoder: | |
def __init__(self, optimizer='adam', loss='mse'): | |
self.optimizer = optimizer | |
self.loss = loss | |
self.n_features = 1 | |
def build_model(self): |
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.cluster import AgglomerativeClustering | |
clusters = 3 | |
y_pred = AgglomerativeClustering(n_clusters=clusters).fit_predict(X) | |
from scipy.cluster.hierarchy import linkage, fcluster, dendrogram | |
clusters=5 | |
cls = linkage(X, method='ward') |
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 kenchi.outlier_detection.statistical import HBOS | |
hbos = HBOS(novelty=True).fit(X) | |
y_pred = hbos.predict(X) |
NewerOlder