import pandas as pd
from sklearn.tree import DecisionTreeRegressor
from sklearn import preprocessing
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import GridSearchCV
# 读取含有热误差数据的CSV文件
train_file = open('data8.csv', encoding='utf-8')
train_df = pd.read_csv(train_file)
# 读取测试集的含有热误差数据的CSV文件
test_file = open('data.csv', encoding='utf-8')
test_df = pd.read_csv(test_file)
# 对训练集进行数据预处理
X_train = train_df.iloc[:, :-1]
Y_train = train_df.iloc[:, -1]
X_train_scaled = preprocessing.scale(X_train)
# 对测试集进行数据预处理
X_test = test_df.iloc[:, :-1]
Y_test = test_df.iloc[:, -1]
X_test_scaled = preprocessing.scale(X_test, with_mean=X_train_scaled.mean(axis=0)[0], with_std=X_train_scaled.mean(axis=0)[0])
X = pd.concat([test_df.iloc[:, :-1], train_df.iloc[:, :-1]], axis=1)
Y = pd.concat([test_df.iloc[:, -1], train_df.iloc[:, -1]], axis=1)
X_test.columns = X_train.columns
# 创建决策树模型
dt = DecisionTreeRegressor()
# 定义网格搜索参数
param_grid = {
'max_depth': [1,2,3,4,5,6,7,8,9],
'min_samples_split': [2, 4, 6],
'min_samples_leaf': [1, 2, 3]
}
# 进行网格搜索优化
grid = GridSearchCV(dt, param_grid, cv=5)
grid.fit(X, Y)
grid_search = GridSearchCV(DecisionTreeRegressor(), param_grid, cv=5)
grid_search.fit(X_train, Y_train)
best_model = grid_search.best_estimator_
# 输出最优参数和模型得分
print('Best Parameters:', grid.best_params_)
# 定义新的温度数据
# 输出预测结果
Y_pred = best_model.predict(X_test)
mse = mean_squared_error(Y_test, Y_pred)
print(f"MSE: {mse:.4f}")
print(Y_pred)
X_test = pd.concat([X_train, X_test], axis=0, ignore_index=True)
预测的误差有点大,能不能帮忙降一点
runfile('C:/Users/86191/.spyder-py3/untitled7.py', wdir='C:/Users/86191/.spyder-py3')
Best Parameters: {'max_depth': 8, 'min_samples_leaf': 2, 'min_samples_split': 2}
MSE: 25.0850
[ 8.699 8.699 8.699 17.013 17.013 17.013
17.013 28.31 28.31 28.31 36.306 36.306
36.306 36.306 36.306 36.306 36.306 38.764
38.764 41.458 48.499 48.499 48.499 48.499
53.0685 53.0685 53.0685 53.0685 53.0685 53.0685
53.0685 53.0685 53.0685 53.0685 53.0685 53.0685
53.0685 53.0685 53.0685 53.0685 54.123 54.123
54.123 54.123 54.123 54.123 54.123 54.123
54.123 54.123 54.123 54.123 54.123 54.123
54.123 54.123 54.123 54.808 54.808 54.808
54.808 54.808 54.808 54.808 54.808 55.543
56.323 56.133 55.46975 55.46975 55.46975 55.46975
55.46975 55.31866667 55.31866667 55.31866667 55.31866667 55.31866667
55.31866667 55.31866667 55.31866667 55.31866667 55.31866667 54.594
54.594 54.594 54.594 54.594 ]
一是由于我国道路环境和交通构成相对复杂、机动车驾驶人驾驶行为多样化,自动驾驶汽车正确识别环境并做出准确响应是面临的挑战之一;同时,针对我国道路的场景库搭建难度大,未能完全满足自动驾驶模拟需求;
二是由于无人驾驶汽车和有人驾驶汽车混行,自动驾驶汽车如何正确感知其他车辆,做出计算,并以此完成执行层的应对、向外界环境发出信号,最终实现与人工驾驶汽车的有效协同并行,也是面临的挑战之一。