LasseRegin / SVM-w-SMO

Simple implementation of a Support Vector Machine using the Sequential Minimal Optimization (SMO) algorithm for training.
MIT License
117 stars 55 forks source link

calc_w function #2

Closed oooook0 closed 6 years ago

oooook0 commented 6 years ago

Hey Lasse,

The calc_w function in your SVM function seems wrong, it should return a vector but it ends up with a matrix. I rewrote the calc_w as follow, it worked, let me know what you think.

 def calc_w(self, alpha, y, X):
        X_t = X.transpose()
        X_ta = np.matmul(X_t, X)
        X_tai = np.linalg.inv(X_ta)
        ols = np.matmul(X_tai, X_t)
        ols = np.matmul(ols, y)
        return ols