sklearn糖尿病多元线性回归
时间: 2023-11-26 12:44:22 浏览: 108
sklearn+python:线性回归案例
好的,针对您的问题,我可以给出以下代码示例:
```python
from sklearn import datasets
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
# 加载糖尿病数据集
diabetes = datasets.load_diabetes()
# 划分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(diabetes.data, diabetes.target, test_size=0.2, random_state=42)
# 创建线性回归模型
model = LinearRegression()
# 训练模型
model.fit(X_train, y_train)
# 在测试集上进行预测
y_pred = model.predict(X_test)
# 输出模型评估指标
print("模型评估指标:")
print("训练集得分:{:.2f}".format(model.score(X_train, y_train)))
print("测试集得分:{:.2f}".format(model.score(X_test, y_test)))
```
阅读全文