regression

构建模型步骤:

  • Step1:选择模型
  • Step2:样本
  • Step3:迭代(梯度下降)
    技巧:
  • 多类的回归
  • overfitting
  • Regularization正则化
    (1)lambda的选择

Step1:选择模型

线性y=wx或者其他

Step2:样本

在这里插入图片描述

(1)样本带入模型:

在这里插入图片描述

(2)Loss Function:

真实值和预测值的误差:
在这里插入图片描述

(3)选择最好的参数:

在这里插入图片描述

Step3:迭代

梯度下降

一开始随机选择参数,此时预测值和误差值的很大的,将每一个位置的参数值画出以下曲线图:
在这里插入图片描述
梯度下降:对初始随机参数w0的模型y=b+w0*x求导即斜率值

  • 当斜率为负值时,增加w,可使误差向减小的方向前进
  • 当斜率为正值时,减小w,可使误差向减小的方向前进
更新参数:w1=初始化参数w0 - 求导的值乘以学习率

更新参数可以使模型不断优化
在这里插入图片描述
在这里插入图片描述
如果是多参数的,求偏导即可。

1、overfitting

第一个图为对训练集的拟合
第二个图为对测试集的拟合
在这里插入图片描述
不同阶数的模型所得到的误差:
模型的复杂度并不是越大越更好,会出现过拟合,从而导致在train集上的error很小,但在test集上的error很大。
在这里插入图片描述

2、多类的回归

当出现以下的数据集时如何拟合呢?

在这里插入图片描述
将数据分成不同种类,重新设计模型
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
添加更多的特征:在这里插入图片描述

3、Regularization正则化

对Loss Function增加参数惩罚项,训练得到的参数w会是一个接近0且较平滑的数。
在这里插入图片描述
参数w越接近0,遇到新的样本时,得到新的结果y1即为原来样本的y+wi*∆x,w越小,则y1越小,所以噪声点对于模型的影响较小
在这里插入图片描述

(1)lambda的选择:

  • lambda越大,w参数的分布会越平滑,但lambda太大,会导致梯度下降时,忽视了w对模型对样本的拟合,过多的重视w的平滑(因为w惩罚项远大于对样本的拟合的误差)
  • lambda越小,w参数分布不均衡,容易过于重视异常点,对模型稳定性影响较大
    在这里插入图片描述
### Network Regression in Machine Learning or Deep Learning Network regression refers to a type of supervised learning problem where the goal is to predict continuous-valued outputs based on input features. In both machine learning and deep learning, network regression can be implemented using various algorithms such as linear regression, neural networks, decision trees, etc., depending on the complexity of the data and the desired accuracy. In the context of machine learning, one common approach involves utilizing libraries like `scikit-learn` for implementing simple models. For instance, consider the following example that demonstrates how to perform linear regression: ```python import numpy as np from sklearn.linear_model import LinearRegression from sklearn.preprocessing import StandardScaler # Generate random dataset with noise np.random.seed(1) X = np.random.rand(100, 1) * 2 - 1 epsilon = np.random.randn(*X.shape) * 0.1 y = np.sin(np.pi * X) + epsilon # Scale the inputs scaler = StandardScaler() X_scaled = scaler.fit_transform(X) # Initialize and fit the model model = LinearRegression() model.fit(X_scaled, y.ravel()) # Predictions predictions = model.predict(X_scaled) ``` This code snippet illustrates generating synthetic data, scaling it appropriately, fitting a linear regression model, and making predictions accordingly[^2]. For more complex scenarios involving non-linear relationships between variables, artificial neural networks (ANNs), particularly those incorporating activation functions like ReLU, are often employed within deep learning frameworks. These ANNs consist of multiple layers—input layer(s), hidden layer(s), output layer—and employ backpropagation along with optimization techniques during training phases to adjust weights iteratively until convergence criteria are met[^3]. Hyperparameters play an essential role here; they include but not limited to learning rate (`learningrate`) controlling step size at each iteration while moving toward minimizing loss function value over epochs count among others affecting overall performance significantly when tuning these settings manually versus automated methods available today through tools provided by TensorFlow/Keras API packages designed specifically around simplifying this process further without losing flexibility needed per project requirements individually tailored solutions possible too!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值