Jun-10-2020, 02:12 PM
I was trying to write some simple code to practice using the linear regression in sklearn. For God knows what reason, LinearRegression.fit(x,y) expects x to be a 2d array and y to be a 1d array. That means if x is actually has 1d data, it needs to be expressed with:
[[
.
.
.
numbers
.
.
.
]]
Note that it has 2 sets of brackets, not just 1 set of brackets.
I wrote a for loop to delete nan values and had a line of code
x = np.delete(x,i)
Apparently this shitty line of code changed x to a 1d array without telling me! Then my code wouldn't work and I didn't know why! If there is a syntax error in that code, I want to be told! I don't want it to be fixed without telling me!
I fixed it by writing the line
x = np.reshape(x,(x.size,1))
Python tries to help me like this a lot and it makes me mad. I hate that it loops back around when indices are negative, instead of giving me an out of bounds error. I hate that it will automatically fix the type for me instead of giving me an error. It makes it so much harder to find the source of the problem. I learned C++ before python, and so far it seems to me that C++ is superior in all respects. It is faster, you can do more things with it (try writing for(int i = 10; i > -1; i-=2){} in python), and all of the user friendliness of python (such as the existence of lists) could be added to C with some libraries. I hate python so much right now. This project should have taken 30 minutes and it ended up taking 3 hours because python kept trying to help me without telling me what it had done. I know if I had known what I was doing it wouldn't have taken that long, but I hadn't used sklearn on my own before and I hadn't used matlab in a few years, so I checked lots of other things first before realizing that python had done something in secret without telling me again.
[[
.
.
.
numbers
.
.
.
]]
Note that it has 2 sets of brackets, not just 1 set of brackets.
I wrote a for loop to delete nan values and had a line of code
x = np.delete(x,i)
Apparently this shitty line of code changed x to a 1d array without telling me! Then my code wouldn't work and I didn't know why! If there is a syntax error in that code, I want to be told! I don't want it to be fixed without telling me!
I fixed it by writing the line
x = np.reshape(x,(x.size,1))
Python tries to help me like this a lot and it makes me mad. I hate that it loops back around when indices are negative, instead of giving me an out of bounds error. I hate that it will automatically fix the type for me instead of giving me an error. It makes it so much harder to find the source of the problem. I learned C++ before python, and so far it seems to me that C++ is superior in all respects. It is faster, you can do more things with it (try writing for(int i = 10; i > -1; i-=2){} in python), and all of the user friendliness of python (such as the existence of lists) could be added to C with some libraries. I hate python so much right now. This project should have taken 30 minutes and it ended up taking 3 hours because python kept trying to help me without telling me what it had done. I know if I had known what I was doing it wouldn't have taken that long, but I hadn't used sklearn on my own before and I hadn't used matlab in a few years, so I checked lots of other things first before realizing that python had done something in secret without telling me again.