机器学习笔记-Python

机器学习流程:数据收集--数据清洗--特征工程--数据建模

 误差项定义

拟合的平面: h_\theta\left ( x \right )= \theta _1+\theta _2x_1+\theta _3x_2  

\theta _0 是偏置项

整合: \sum_{i=0}^{n}\theta _ix_i = \theta ^{T}x

y^{i} = \theta ^{T}x + \varepsilon ^{i} 

梯度下降

#小批量梯度下降
import numpy as np

class LinearRegression:
    def __init__ (self,data,labels,polynomial_degree=0,num_features=2):
        self.data = data
        self.theta = np.zeros(num_features,1)
        self.labels = labels
    
    def train(self,alpha,num_iterations = 500):
        return

    def gradient_descent(self,alpha, num_iterations):
        for i in range(num_iterations):
            self.gradient_descent(alpha)
        return
    
    def gradient_step(self,alpha):
        num_example = self.data.shape[0]
        prediction = LinearRegression.hypothesis(self.data,self.theta)
        delta = prediction - self.labels
        theta = self.theta
        theta = theta - alpha*(1/num_example)*(np.dot(delta.T,self.data)).T
        self.theta = theta

    def hypothesis(data,theta):
        prediction = np.dot(data,theta)
        return prediction

plotly工具包

sklearn 工具包

混淆矩阵

第二周

多维特征 ---多元线性回归

向量化

f = np.dot(w,x)+b

特征缩放

图像应该是平滑下降的,可能存在bug或者学习率太大。

第三周

逻辑回归

决策边界

逻辑回归中的代价函数

过度拟合(overfitting)

解决方法:
  1. 增加训练数据
  2. 对特征进行筛选 select features
  3. 正则化(regularization)--保留所有特征,但是防止特征产生过大影响,这有时会导致过拟合(改变加权)

正则化

---线性回归

 

 

---逻辑回归

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值