开发者社区> 问答> 正文

怎样用python代码去计算回归模型的系数和截距呢?

已解决

怎样用python代码去计算回归模型的系数和截距呢?

展开
收起
每天一个小bug 2022-07-27 16:48:08 688 0
1 条回答
写回答
取消 提交回答
  • 推荐回答

    代码如下:

    import matplotlib.pyplot as plt

    def drawplt():

    plt.figure()

    plt.title(' Cost and Income Of a Film')

    plt. xlabe1(' Cost(Mi1lion Yuan)')

    plt.ylabel(' Income (Million Yuan)')

    plt.axis([0,25,0,60])

    plt. grid(True)

    X=[[6],[9],[12],[14],[16]]

    y =[[9],[12],[29],[35],[59]]

    model = linear_model. LinearRegression()

    model.fit(X,y)

    w=model.coef_

    b=model.intercept_

    其中w就是该回归模型的系数,b为回归模型的截距

    2022-07-27 19:17:20
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载