It seems that there is an error in the code. The error message "Replacement index 14 out of range for positional args tuple" indicates that there is an issue with the formatting of the print statement.

Upon closer inspection, it appears that there are 14 coefficients in the model, but the print statement only has placeholders for 13 coefficients. This is causing the error.

To fix this issue, you can update the print statement to include the correct number of placeholders for the coefficients. Here's an updated version of the print statement:

print('方程:y = {}x1 + {}x2 + {}x3 + {}x4 + {}x1^2 + {}x2^2 + {}x3^2 + {}x4^2 + {}x1x2 + {}x1x3 + {}x1x4 + {}x2x3 + {}x2x4 + {}x3x4 + {}'.format(
    coefficients[1], coefficients[2], coefficients[3], coefficients[4], coefficients[5], coefficients[6], coefficients[7], coefficients[8],
    coefficients[9], coefficients[10], coefficients[11], coefficients[12], coefficients[13], intercept))

This should fix the error and properly display the equation with all the coefficients.

import pandas as pdimport numpy as npfrom sklearnpreprocessing import PolynomialFeaturesfrom sklearnlinear_model import LinearRegressionfrom sklearnmetrics import r2_score# 读取Excel文件data = pdread_exce

原文地址: https://www.cveoy.top/t/topic/iw82 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录