Skip to content

Instantly share code, notes, and snippets.

View akashjaswal's full-sized avatar

Akashdeep Singh Jaswal akashjaswal

View GitHub Profile
@akashjaswal
akashjaswal / vectorized_logistic_regression.py
Last active July 1, 2023 06:57
Vectorized Implementation of Logistic Regression using Numpy
'''
Logistic Regression - Vectorized Implementation w/ Numpy
Setup:
- features X = Feature Vector of shape (m, n) [Could append bias term to feature matrix with ones(m, 1)]
- Target y = discrete variable - shape (m, 1) (Consider Binary for now)
- Weights = Weight matrix of shape (n, 1) - initialize with zeros
- Standardize features to have zero mean and unit variance.
Gradient Descent Algorithm:
@akashjaswal
akashjaswal / vectorized_linear_regression.py
Last active June 23, 2023 12:58
Vectorized Implementation of Linear Regression using Numpy
'''
Linear Regression - Vectorized Implementation w/ Numpy
Setup:
- features X = Feature Vector of shape (m, n) [Could append bias term to feature matrix with ones(m, 1)]
- Target y = continuous variable - shape (m, 1)
- Weights = Weight matrix of shape (n, 1) - initialize with zeros
- Standardize features to have zero mean and unit variance.
import re
from collections import Counter, defaultdict
def build_vocab(corpus: str) -> dict:
"""Step 1. Build vocab from text corpus"""
# Separate each char in word by space and add mark end of token
tokens = [" ".join(word) + " </w>" for word in corpus.split()]