逻辑回归线性回归复现

这篇博客主要介绍了如何复现逻辑回归和线性回归的代码实现。首先,作者展示了sigmoid函数的细节,随后详细讲解了逻辑回归的实现过程。
摘要由CSDN通过智能技术生成

线性回归代码:

# -*- coding: utf-8 -*-
"""
Created on Tue Nov 19 23:19:49 2019

@author: 86135
"""

import numpy as np
import matplotlib.pyplot as plt
class LinearRegression():
    def_init_(self):
        self._coef_=None
        self.interception_=None
        self._theta=None
    def fit_normal(self,x_train,y_train):
        assert x_train.shape[0]==y_train.shape[0],\
                            "the size of x_train must be equal to the size of y_train"
        x_b=np.hatack([np.ones((len(x_train),1)),x_train])
        self.theta=np.linalg.inv(x_b.T.dot(x_b)).dot(x_b.T).dot(y_train);
        self.interception_=self.theta[0]
        self.coef_=self._thta[1:]
        return self
    def predict(self,x_predict):
        assert self.self.interception_is not None and self.coef is not None,\
        "must fit before predict !"
        assert x_predi
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值