Lets start with the easy fact that Marty McFly is a teenager. If his teachers dislike Doc Brown, this is a good enough reason for Marty to continue being friends with him, just to be anti-authoritarian.
At the beginning of the first movie, Marty isn't that popular. His dad is a loser, his uncle is in prison, his mother is an alcoholic (Lorraine is drinking vodka liberally at the start), his adult brother lives at home and works in fast food, and he's in an unpopular band that didn't finish one song in a battle of the bands try-out. At some point Marty probably just met Doc who is also an outsider in Hill Valley and sprung up a friendship with him.
But lastly, Back to the Future plays hard and fast with causality. Why is Marty friends with Doc, well because Doc met Marty in 1955, who helped him pioneer his flux capacitor.
In original 1955, did the Doc know that the Flux Capacitor would work, or did he think it would be a failure and the only reason it worked was because Marty came back in time to tell him it worked, and then Doc knew he couldn't tell Marty that they met to make sure Marty would go back in time to meet him to make sure the flux capacitor was invented... whoa... this is heavy.