将唯一ID与预测结果结合起来进行python建模
我正在做建模,比如说逻辑回归,需要将结果保存在数据帧中(预测结果和唯一ID) 预测代码将唯一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
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=';')