How do i print out the right Id with my output
<p>I am working with sklearn and pandas and my prediction is coming out as an array without the right id, which has been set as the index.</p>

<p>My code:</p>

<pre><code>train = train.set_index('activity_id')
test = test.set_index('activity_id')

y_train = train['outcome']
x_train = train.drop('people_id', axis=1)
x_test = test

model = DecisionTreeClassifier(min_samples_leaf=100)

model.fit(x_train,y_train)


scores = cross_val_score(model, x_train,y_train, cv=10)
print('mean: {:.3f} (std: {:.3f})'.format(scores.mean(), scores.std()), end='\n\n')
print(model.score(x_train,y_train))
#make predictions
y_pred = model.predict(x_test)
</code></pre>

<p>Any thoughts on how i can get them to print out with the right activity_id list? Thanks!</p>

<p>From what you have written I believe you are trying to show your index for x_test next to the y_pred values generated by x_test.</p>

<p>This can be done by turning the numpy array output from <code>model.predict(x_test)</code> into a DataFrame. Then we can set the index of the new DataFrame to be the same as that of <code>x_test</code>.</p>

<p>Here is an example,</p>

<pre><code>df_pred = pd.DataFrame(y_pred, index=x_test.index, columns=['y_pred'])
</code></pre>

python pandas scikit-learn