after predicting the target value for the classification problem trying to get the predicted values in a .csv file along with the id of particular data instance but getting the unnecessary row numbers.
x_train,x_test,y_train,y_test = train_test_split(x,y, random_state=101,strtify =y) cls = DecisionTreeClassifier() cls.fit(x_train,y_train) pred = cls.predict(x_test) prediction = pd.DataFrame({'id':x_test['id'],'target':pred}) prediction.to_csv("path/prediction.csv")
Advertisement
Answer
You index=False
, doc specifies this argument
prediction.to_csv("path/prediction.csv",index=False)