# Metis- A Machine Learning Library in Python | DevBlog 1: Linear Regression

This is the first in a series of Devblogs, as I like to call it, where I will try to develop a fully-fledged machine learning library in python. Without any further ado, let’s get started.

# Initializing the code

First, I initialized an empty git repository in my folder. I organized my files like a traditional module with __init__.py and stuff. Next up we’re gonna create a regression folder where the regression methods like Linear Regression, Logistic Regression, and even Polynomial Regression are gonna reside.

# The Linear Regression Class

I’m thinking of making this whole library object-oriented as is the case with most libraries. It makes it easier to code and debug. I want the class to take in two variables X, Y where X is an array of the input data points and Y is an array of outputs. Furthermore, I also want both of them to be np.ndarrays for ease of use. We’ll code the preprocessing functions in a later Devlog.

I’ll also define the weight and bias as well. Let’s assume the X vector is of the shape (1 x n) where n is the number of data points. Then the weight should have the shape (1 x n) where n is the number of data points. To arrive at the (1 x 1) shape of the output we essentially matrix multiply the transpose of the weight vector to the input vector.

# Deriving the Linear Regression Formula

Deriving this formula would be a pain in the ass especially since Medium has no latex support. So here’s a wonderful video by CodeEmporium that explains the derivation. Try to go through it and understand the math behind the code. It’ll help you appreciate it more.

# Coding the predict and fit functions

All that’s left to do is to code predict and fit functions. Here’s that

# Conclusion

That’s it for today’s Devlog. I’m planning to post these articles 1 per day. If that doesn’t happen, expect an article every three-four days. Thank you for reading this article, if you enjoyed it leave a clap and a comment. Thank you.

*As Medium hasn’t integrated payments to India there is no way for me to monetize my content. If you like my article, please consider **Buying me a cup of coffee*