Skip to content

Instantly share code, notes, and snippets.

View rasbt's full-sized avatar

Sebastian Raschka rasbt

View GitHub Profile
@rasbt
rasbt / .vimrc
Last active August 28, 2017 10:12
vimrc file for c++ and python code syntax support
" Sebastian Raschka
" 09/11/2013
"
syntax on
set nonumber
set ruler
set tabstop=4
set shiftwidth=4 " controls the depth of autoindentation
@rasbt
rasbt / eng_detect.py
Last active August 29, 2015 14:07
English language detection
import nltk
def eng_ratio(text):
''' Returns the ratio of non-English to English words from a text '''
english_vocab = set(w.lower() for w in nltk.corpus.words.words())
text_vocab = set(w.lower() for w in text.split() if w.lower().isalpha())
unusual = text_vocab.difference(english_vocab)
diff = len(unusual)/len(text_vocab)
return diff
@rasbt
rasbt / plot_decision_region_bug_1.py
Created September 13, 2016 14:39
plot_decision_region bug
from matplotlib.colors import ListedColormap
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets
from sklearn.linear_model import LogisticRegression
def plot_decision_regions(X, y, classifier, resolution=0.1):
# setup marker generator and color map
markers = ('s', 'x', 'o', '^', 'v')
@rasbt
rasbt / ipnbdoctest.py
Created March 9, 2017 17:38 — forked from minrk/ipnbdoctest.py
simple example script for running and testing notebooks.
#!/usr/bin/env python
"""
simple example script for running and testing notebooks.
Usage: `ipnbdoctest.py foo.ipynb [bar.ipynb [...]]`
Each cell is submitted to the kernel, and the outputs are compared with those stored in the notebook.
"""
# License: Public Domain, but credit is nice (Min RK).
@rasbt
rasbt / vgg16.py
Created March 3, 2019 06:34
Speed comparison DataLoader vs in-memory
import time
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets
from torchvision import transforms
from torch.utils.data import DataLoader
if torch.cuda.is_available():
@rasbt
rasbt / miniforge-m1-pytorch-env.yml
Created February 6, 2022 16:12
Relatively Minimal Miniforge environment for M1 Mac
name: base
channels:
- conda-forge
dependencies:
- absl-py=1.0.0=pyhd8ed1ab_0
- aiohttp=3.8.1=py39h5161555_0
- aiosignal=1.2.0=pyhd8ed1ab_0
- anyio=3.5.0=py39h2804cbe_0
- appnope=0.1.2=py39h2804cbe_2
- argh=0.26.2=pyh9f0ad1d_1002
@rasbt
rasbt / .zshrc
Created February 10, 2022 18:37
Minimal zshell config
### EYECANDY ###
autoload -U colors && colors
PS1="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "
export CLICOLOR=1
#export LSCOLORS=ExFxBxDxCxegedabagacad
#alias ls='ls -GFh'
### END
@rasbt
rasbt / classifier-calibration.py
Created April 13, 2022 16:36
Classifier Calibration -- A Minimal Example
import numpy as np
from sklearn.datasets import make_classification
from sklearn.model_selection import cross_val_score
from sklearn.tree import DecisionTreeClassifier
from sklearn.calibration import CalibratedClassifierCV
X, y = make_classification(
n_samples=1000, n_features=5, n_redundant=2,
n_clusters_per_class=1, random_state=123)
@rasbt
rasbt / onehot-numeric-mixed-data.csv
Last active July 7, 2022 16:44
A 3-class sample dataset with numeric and categorical features
categorical measurement1 measurement2 label measurement3
F 1.428571429 2.721312902 0 2.089
R 0.685939167 0.982976329 0 0.637
P 1.055817143 0.624210021 0 0.226
S 0.995956364 0.321101265 0 0.138
R 1.376773333 1.578308527 0 0.478
R 0.837229167 1.549647481 0 0.169
Q 1.552222941 2.641907404 0 1.599
E 1.492519333 2.634558656 0 1.052
W 0.816596667 1.168353374 0 0.432
@rasbt
rasbt / video-subtitles-via-whisper.py
Last active September 19, 2023 21:14
Script that creates subtitles (closed captions) for all MP4 video files in your current directory
# Sebastian Raschka 09/24/2022
# Create a new conda environment and packages
# conda create -n whisper python=3.9
# conda activate whisper
# conda install mlxtend -c conda-forge
# Install ffmpeg
# macOS & homebrew
# brew install ffmpeg
# Ubuntu