Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将唯一ID与预测结果结合起来进行python建模_Python_Pandas - Fatal编程技术网

将唯一ID与预测结果结合起来进行python建模

将唯一ID与预测结果结合起来进行python建模,python,pandas,Python,Pandas,我正在做建模,比如说逻辑回归,需要将结果保存在数据帧中(预测结果和唯一ID) 预测代码 from sklearn.linear_model import LogisticRegression lr_clf.fit(X_train, y_train) predictions=lr_clf.predict(test_data) 我希望在预测的同时,我还应该在预测数据帧的X_列中有一个唯一标识符(现在预测是一个numpy数组)。假设唯一ID是X\U列中的ID列 预期产量 predictions I

我正在做建模,比如说逻辑回归,需要将结果保存在数据帧中(预测结果和唯一ID)

预测代码

from sklearn.linear_model import LogisticRegression
lr_clf.fit(X_train, y_train)
predictions=lr_clf.predict(test_data)
我希望在预测的同时,我还应该在预测数据帧的X_列中有一个唯一标识符(现在预测是一个numpy数组)。假设唯一ID是X\U列中的
ID

预期产量

predictions  ID
11           1000
123          1001
and so on

您可以包括来自X_train的唯一ID以及以下预测

#Modelling    
from sklearn.linear_model import LogisticRegression
lr_clf.fit(X_train, y_train)
predictions=lr_clf.predict(test_data)


#Add ID along with prediction and save the pandas dataframe
 predictions_df=pd.DataFrame(data={"ID":X_train["ID"],"Predictions":predictions})
 predictions_df.to_csv(path="predictions_df.csv",index=False,quoting=3,sep=';')