Search code examples
pythonpandasdataframescikit-learnprediction

Pandas: Combining Actual and Prediction Values


I’m trying to combine the actual target values and predicted target value as a dataframe. However, I’m getting the following error. Not sure why this is happening.

a = pd.DataFrame(y_test, columns=['Actual'])
b = pd.DataFrame(final_model.predict(X_test), columns=['Predictions'])
c = pd.concat([a, b])
c.head()

Actual Vs Prediction


Solution

  • @nimbous already answered but if you want less intermediate steps, use a dictionary to create a df.

    c = pd.DataFrame({"Actual": y_test, "Predictions": final_model.predict(X_test)})