import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
import matplotlib.pyplot as plt
import numpy as np
file_path = r"D:\表型图片\999.xlsx"
df = pd.read_excel(file_path)
print("Data Overview:")
print(df.head())
X = df[['length', 'width']]
y = df['area']
# 设置随机种子以保证结果可复现
np.random.seed(42)
num_iterations = 10
fig, axes = plt.subplots(nrows=2, ncols=5, figsize=(20, 8))
axes = axes.flatten()
for i in range(num_iterations):
# 不放回随机抽取5个数据点
indices = np.random.choice(X.index, 5, replace=False)