Pandas 熊猫-在对其他值应用线性回归后跟踪值

Pandas 熊猫-在对其他值应用线性回归后跟踪值,pandas,linear-regression,Pandas,Linear Regression,我正在尝试对熊猫数据框中的一系列变量应用线性回归,但player_id除外,这只是跟踪被预测玩家的一种方法 print (df.info()) player_id 1601 non-null int64 X1 1601 non-null float64 X2 1601 non-null float64 X3 1601 non-null float64 X4 1601 n

我正在尝试对熊猫数据框中的一系列变量应用线性回归,但player_id除外,这只是跟踪被预测玩家的一种方法

print (df.info())

player_id        1601 non-null int64
X1               1601 non-null float64
X2               1601 non-null float64
X3               1601 non-null float64
X4               1601 non-null float64
X5               1601 non-null float64
X6               1601 non-null float64
X7               1601 non-null float64
X8               1601 non-null float64
Y                1601 non-null float64
这是我如何尝试声明变量的:

df = df[['X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'Y']]

X = df.drop(axis=1, columns=['Y'])
# normalize data
X = X.astype('float32') / 255.

# independent variable
y = df['Y']
# normalize data
y = y.astype('float32') / 255.

model = LinearRegression()
model.fit(X, y)

y_hat = model.predict(X)

问题是:一旦我有了我的预测值数组,我如何跟踪它们回到每个玩家的id,以便知道预测值指的是哪个玩家


例如:


max(network.predict(X))指向哪个播放器?

它将按照与您提供的X相同的顺序返回值列表。因此,对于X中的第i行,y的第i个值是预测值。

这是有效的:

for i, value in enumerate(list(y_hat.flatten())):
    print (df.iloc[i]['player_id'])
    df['prediction'].iloc[i] = value.astype('float32')

非常感谢。这会给我索引。但我不需要吵架。我需要在该行中获得一个值,player_id,例如:哪个player_id
max(network.predict(X)
指的是?我不知道您使用的是什么模型/库等。但在对预测进行“max”之前,您总是希望首先将预测与相应的X关联起来。如果您只尝试分析一组没有索引的预测,您就无法知道它属于谁。基本上,我知道的库会按照您的顺序为您提供预测提供了数据,你必须在做任何其他事情之前将其链接回来。因此,对于df[index,X1,X2…],当你得到预测时,你将它们作为df[index,Y_hat]附加到你的df上