多项式回归 Python sklearn库 LinearRegression(学习笔记)

这篇博客探讨了使用Python的sklearn库进行多项式回归,通过计算r^2分数,发现二项式和三项式回归展现出最佳的拟合效果,但随着项数增加,出现了过度拟合问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures

font=FontProperties(fname=r"C:\Windows\Fonts\msyh.ttc",size=15)#设置中文字体

def runplt():
    plt.figure()
    plt.title('身高与体重一元关系',fontproperties=font)
    plt.xlabel('身高(米)',fontproperties=font)
    plt.ylabel('体重(千克)',fontproperties=font)
    plt.axis([0.5,2,5,85],fontproperties=font)
    plt.grid(True)
    return plt

#导入数据
X_train=[[0.86],
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值