Python 如何创建机器学习模型列表?
我正在30个不同的数据集(具有相同的维度)上训练一系列机器学习模型。我想将这些模型存储在列表中。所有模型都是相同的,即DecisionTreeRegressor(),但每个模型都在不同的数据集上进行训练Python 如何创建机器学习模型列表?,python,pandas,list,numpy,machine-learning,Python,Pandas,List,Numpy,Machine Learning,我正在30个不同的数据集(具有相同的维度)上训练一系列机器学习模型。我想将这些模型存储在列表中。所有模型都是相同的,即DecisionTreeRegressor(),但每个模型都在不同的数据集上进行训练 model_list = [] for i in range(30): model = DecisionTreeRegressor(max_depth= None, criterion ='mse') model.fit(x[i], y[i]) model_list.ap
model_list = []
for i in range(30):
model = DecisionTreeRegressor(max_depth= None, criterion ='mse')
model.fit(x[i], y[i])
model_list.append(model)
我可以使用上面的代码,但它将为每个模型存储具有相同名称的所有模型,即“模型”。我想用不同的名称来存储它们,比如['model_1'、'model_2'、'model_3'等等。]
以下是数据x和y的尺寸。供你参考。请帮忙
x.shape=30
,y.shape=30
x[0].shape = (500, 5) and y[0].shape = (500)
您可以像下面这样做,或者在for
循环中添加名称
model_df=pd.DataFrame()
为什么不创建一个包含名称和模型的元组呢?
test_model = 'x[0].shape = (500, 5) and y[0].shape = (500)'
for i in range(30):
model_df = model_df.append([test_model])
model_df=model_df.reset_index(drop=True)
model_df['model_name'] = ['model no: ']+model_df.index.astype(str)
print(model_df)
0 model_name
0 x[0].shape = (500, 5) and y[0].shape = (500) model no: 0
1 x[0].shape = (500, 5) and y[0].shape = (500) model no: 1
2 x[0].shape = (500, 5) and y[0].shape = (500) model no: 2
3 x[0].shape = (500, 5) and y[0].shape = (500) model no: 3
4 x[0].shape = (500, 5) and y[0].shape = (500) model no: 4
5 x[0].shape = (500, 5) and y[0].shape = (500) model no: 5
6 x[0].shape = (500, 5) and y[0].shape = (500) model no: 6
7 x[0].shape = (500, 5) and y[0].shape = (500) model no: 7
8 x[0].shape = (500, 5) and y[0].shape = (500) model no: 8
9 x[0].shape = (500, 5) and y[0].shape = (500) model no: 9
10 x[0].shape = (500, 5) and y[0].shape = (500) model no: 10
11 x[0].shape = (500, 5) and y[0].shape = (500) model no: 11
12 x[0].shape = (500, 5) and y[0].shape = (500) model no: 12
13 x[0].shape = (500, 5) and y[0].shape = (500) model no: 13
14 x[0].shape = (500, 5) and y[0].shape = (500) model no: 14
15 x[0].shape = (500, 5) and y[0].shape = (500) model no: 15
16 x[0].shape = (500, 5) and y[0].shape = (500) model no: 16
17 x[0].shape = (500, 5) and y[0].shape = (500) model no: 17
18 x[0].shape = (500, 5) and y[0].shape = (500) model no: 18
19 x[0].shape = (500, 5) and y[0].shape = (500) model no: 19
20 x[0].shape = (500, 5) and y[0].shape = (500) model no: 20
21 x[0].shape = (500, 5) and y[0].shape = (500) model no: 21
22 x[0].shape = (500, 5) and y[0].shape = (500) model no: 22
23 x[0].shape = (500, 5) and y[0].shape = (500) model no: 23
24 x[0].shape = (500, 5) and y[0].shape = (500) model no: 24
25 x[0].shape = (500, 5) and y[0].shape = (500) model no: 25
26 x[0].shape = (500, 5) and y[0].shape = (500) model no: 26
27 x[0].shape = (500, 5) and y[0].shape = (500) model no: 27
28 x[0].shape = (500, 5) and y[0].shape = (500) model no: 28
29 x[0].shape = (500, 5) and y[0].shape = (500) model no: 29