LinearRegression.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:tinyml 作者: parasdahal 项目源码 文件源码
def __init__(self, table,reg=False,lamda=0):
        """Initializes Class for Linear Regression

        Parameters
        ----------
        table : ndarray(n-rows,m-features + 1)
            Numerical training data, last column as training values
        reg : Boolean
            Set True to enable regularization, false by default

        """
        #regularization parameters
        self.reg = reg
        self.lamda = lamda

        self.num_training = np.shape(table)[0]
        # remove the last column from training data to extract features data
        self.X = np.delete(table, -1, 1)
        # add a column of ones in front of the training data
        self.X = np.insert(self.X, 0, np.ones(self.num_training), axis=1)
        self.num_features = np.shape(self.X)[1]
        # extract the values of the training set from the provided data
        self.y = table[:, self.num_features - 1]
        # create parameters and initialize to 1
        self.theta = np.ones(self.num_features)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号