Shahid Jamal
Shahid Jamal

Reputation: 13

Submission on Kaggle

Kaggle requires us to upload the CSV file, but I don't understand how to do it. I've a complete code which gives me predictions and I need to write those predictions against their ids and make a CSV file out of them (i.e. containing two columns, one of the id and other of their respective predictions). How do I do it? It'd be great if someone could help me with a bit of sample python code.

First one is the prediction which comes out as a numpy array

array([ 1., 1., 1., 1., 0., 1., 1., 0., 1., 1., 0., 1., 1., 0., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 0., 1., 1., 1., 1., 0., 0., 1., 0., 0., 1., 0., 1., 1., 1., 0., 1., 0., 1., 0., 1., 1., 0., 1., 0., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 0., 1., 0., 1., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 1., 1., 1., 0., 0., 1., 0., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 0., 0., 1., 1., 1., 0., 0., 1., 0., 1., 1., 1., 0., 0., 1., 0., 1., 1., 0., 1., 0., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 0., 0., 1., 1., 0., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 0., 0., 1., 0., 1., 1., 0., 0., 1., 1., 0., 0., 0., 1., 0., 1., 0., 1., 1., 1., 1., 0., 1., 1., 1., 1., 0., 1., 1., 1., 1., 0., 1., 0., 1., 1., 1., 0., 1., 0., 0., 1., 1., 1., 0., 0., 1., 1., 1., 0., 0., 1., 1., 1., 0., 1., 1., 1., 0., 1., 1., 1., 1., 0., 0., 1., 1., 1., 0., 1., 1., 1., 0., 0., 0., 1., 0., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 0., 0., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 0., 1., 1., 0., 0., 1., 0., 0., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 0., 1.])

and the second one is z_test which is a dataframe given by

0 LP001015 1 LP001022 2 LP001031 3 LP001035 4 LP001051 5 LP001054 6 LP001055 7 LP001056 8 LP001059 9 LP001067 10 LP001078 11 LP001082 12 LP001083 13 LP001094 14 LP001096 15 LP001099 16 LP001105 17 LP001107 18 LP001108 19 LP001115 20 LP001121 21 LP001124 22 LP001128 23 LP001135 24 LP001149 25 LP001153 26 LP001163 27 LP001169 28 LP001174 29 LP001176

337 LP002856 338 LP002857 339 LP002858 340 LP002860 341 LP002867 342 LP002869 343 LP002870 344 LP002876 345 LP002878 346 LP002879 347 LP002885 348 LP002890 349 LP002891 350 LP002899 351 LP002901 352 LP002907 353 LP002920 354 LP002921 355 LP002932 356 LP002935 357 LP002952 358 LP002954 359 LP002962 360 LP002965 361 LP002969 362 LP002971 363 LP002975 364 LP002980 365 LP002986 366 LP002989

I've to make a csv file out of these two. Both have shape (367,).

P.S.- I had a Dataframe X_test on which I had to make predictions, so I copied the id column to z_test using .copy() method.

Upvotes: 0

Views: 466

Answers (1)

Agnieszka Walter
Agnieszka Walter

Reputation: 187

You can e.g. create Pandas DataFrame with columns of interest and save it as csv.

submission = pandas.DataFrame({
    "LoanId": LoanId["LoanId"],
    "Prediction": predictions.astype(int)
})

submission.to_csv("kaggle.csv", index = False)

Upvotes: 1

Related Questions