Skip to content

Instantly share code, notes, and snippets.

import statistics
import timeit
import csv
import pandas as pd
import numpy as np
import polars as pl
def measure_performance(func, n_runs=50):
times = timeit.repeat(func, repeat=n_runs, number=1)
import asyncio
import json
import time
from typing import Optional, List
from pydantic import BaseModel, Field
from starlette.responses import StreamingResponse
from fastapi import FastAPI, HTTPException, Request
from numpy import genfromtxt
from sklearn.preprocessing import MinMaxScaler
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
## Data preprocessing
# Load csv dataset into a numpy array
X = genfromtxt('/path/to/dataset', delimiter=',')
# Use MinMaxScaler to scale the data
local cnt = redis.call('INCR', KEYS[1])
if cnt > tonumber(ARGV[1])
then
return redis.call('PTTL', KEYS[1])
end
if cnt == 1
then
redis.call('PEXPIRE', KEYS[1], ARGV[2])
end
return 0