我正在使用 auto-mpg 数据集。我给出了下面数据集的链接:
https://www.kaggle.com/datasets/uciml/autompg-dataset
我给出以下代码:
df = pd.read_csv('data/auto-mpg.csv')
df.head()
df = df.drop('car name', axis=1)
X = df
X.head()
y = df['mpg']
y.head()
SEED = 1
# Split the data into 70% train and 30% test
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=SEED)
# Instantiate a DecisionTreeRegressor dt
dt = DecisionTreeRegressor(max_depth=4, min_samples_leaf=0.26, random_state=SEED)
# Compute the array containing the 10-folds CV MSEs
MSE_CV_scores = - cross_val_score(dt, X_train, y_train, cv = 10,
scoring = 'neg_mean_squared_error', n_jobs = 1)
RMSE_CV = (MSE_CV_scores.mean())**(1/2)
#错误 值错误: 10次都失败了。 您的模型很可能配置错误。 您可以尝试通过设置 error_score='raise' 来调试错误。
以下是有关失败的更多详细信息:
--------------------------------------------------------------------------------
10 fits failed with the following error:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: '?'
该错误是由“?”的存在引起的。在数据中。从 Kaggle 链接中,我注意到马力一栏有它。
您可以替换“?”用 NaN 来指示缺失值,然后使用适当的技术处理这些缺失值。