Skip to content

Instantly share code, notes, and snippets.

import cvxopt
import numpy as np
from .base import BaseModel
class SVMSoftMargin(BaseModel):
def __init__(self, C: float):
self.C = C
import cvxopt
import numpy as np
from .base import BaseModel
class SVM(BaseModel):
def __init__(self):
self._w = None
@nguyenhaidang94
nguyenhaidang94 / pinv.py
Last active April 10, 2022 13:49
Implement pseudo inverse
import numpy as np
def pinv(x: np.ndarray, singular_threshold: float = 1e-10):
"""
Pseudo inverse.\n
Params:
x: matrix to inverse
singular_threshold: threshold to remove singularvalues
"""
@nguyenhaidang94
nguyenhaidang94 / linear_regression.py
Last active April 10, 2022 13:05
Implement linear regression
import numpy as np
from .base import BaseModel
from .helper import pinv
class LinearRegression(BaseModel):
def __init__(self):
self._beta = None