[:, -1] it would give you every last element from second dimension.
In general in python if you provide negative index it will give item from reverse (From right side). So -1 means last element, -2 means second last elements.
For example:
for [:,-1] everything before the comma refers to the row you are extracting and everything after denotes the column. This is similar to python slices. In this case the colon : denotes all rows. -1 denotes you are extracting the last column. Do have a review of slices if you are still unfamiliar about this.
I suppose I asked it wrongly… What I really needed to know was use of [:,-1] with models.predict_proba(X_test) because when I run the code without [:,-1]; I am getting into an error
For eg : testing_probs = models.predict_proba(X_test)
error : - ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series
That’s because you are trying to assign some (a,b) dimension array into the data frame which is not possible. It would be like assigning two or more columns into one. See, “cannot set a frame with”
So [:,-1] gives you a series that can be assigned to the data frame directly.
For example,
This kind of array would be returned and if you try to assign it to one column then there would be an error.