Saving prediction results to CSV

前端 未结 3 1799
遥遥无期
遥遥无期 2020-12-08 17:02

I am storing the results from a sklearn regression model to the varibla prediction.

prediction = regressor.predict(data[[\'X\']])
print(prediction)
         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 17:30

    You can use pandas. As it's said, numpy arrays don't have a to_csv function.

    import numpy as np
    import pandas as pd
    prediction = pd.DataFrame(predictions, columns=['predictions']).to_csv('prediction.csv')
    

    add ".T" if you want either your values in line or column-like.

提交回复
热议问题