AttributeError: 'DataFrame' object has no attribute 'data'. Did you mean: '_data'?
时间: 2023-07-24 14:11:04 浏览: 751
attribute详细介绍
对不起,我在代码示例中犯了一个错误。波士顿房价数据集不是一个DataFrame对象,而是一个Bunch对象,因此没有`data`属性。我会修正这个错误,将数据集加载和划分的代码修改如下:
```python
import numpy as np
import pandas as pd
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import Ridge
from sklearn.neural_network import MLPRegressor
from sklearn.svm import SVR
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
import matplotlib.pyplot as plt
# 加载波士顿房价数据集
boston = load_boston()
X = boston.data
y = boston.target
# 数据集划分为训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# 特征归一化
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
```
非常抱歉给您带来了困惑!
阅读全文