波士顿房价预测(四:利用torch手写线性回归代码,含有L1,L2正则)
导库
from IPython import display
from matplotlib import pyplot as plt
from mxnet import autograd, nd
import random
import pandas as pd
import numpy as np
读取数据:
train_data=pd.read_csv('train_dataset.csv')
test_data=pd.read_csv('test_dataset.csv')
train_price=train_data['PRICE']
del train_data['PRICE']
test_id=test_data['ID']
del test_data['ID']
异常值处理核心函数:
def box_plot_outliers(data_ser, box_scale):
"""
利用箱线图去除异常值
:param data_ser: 接收 pandas.Series 数据格式
:param box_scale: 箱线图尺度,默认用 box_plot(scale=3)进行清洗
:return:
"""
new_up=data_ser.quantile(0.75)
new_low=data_ser.quantile(0.25)
print(new_up,new_low)
iqr = box_scale * (data_ser

该博客介绍了如何使用PyTorch手动实现线性回归模型,包括L1和L2正则化的实现,以预测波士顿地区的房价。通过对数据的预处理,如异常值处理和特征标准化,然后在训练和测试集上应用模型,最终观察不同正则化方法对模型性能的影响。
最低0.47元/天 解锁文章
&spm=1001.2101.3001.5002&articleId=113730514&d=1&t=3&u=9bd14e301349428ebeb62a354a2806df)
843

被折叠的 条评论
为什么被折叠?



