Skip to content

This code does linear regression using scikit-learn and custom NumPy implementation. It loads datasets, removes NaNs, scales features, trains and evaluates models, and plots best fit line. Custom model uses gradient descent. Outputs R2 score, coefficients, and intercept.

License

Notifications You must be signed in to change notification settings

Awaiz-Malik/Simple-Linear_Regression-Using-NumPy-and-Scikit-Learn

Repository files navigation

Simple Linear-Regression Using NumPy and Scikit-Learn

Modelling Linear Regression on X and Y Values from .csv file

This Project explains the implementation of Simple Linear Regression to a dataset using two different methods.

Method 1: Scikit-Learn Library

The first method uses the built-in linear regression model from the scikit-learn library to train the dataset. The following steps are followed:

  1. Import the required libraries (numpy, pandas, matplotlib, and scikit-learn) Load the dataset using pandas read_csv() function
  2. Split the dataset into independent and dependent variables
  3. Train the model using scikit-learn's LinearRegression() function
  4. Test the accuracy of the model using the R-squared score
  5. Visualize the best fit line using Matplotlib

Method 2: NumPy Library

The second method implements simple linear regression using the NumPy library. The following steps are followed:

  1. Import the required libraries (numpy, pandas, and matplotlib)
  2. Load the dataset using pandas read_csv() function
  3. Split the dataset into independent and dependent variables
  4. Initialize coefficients and bias Set the learning rate and number of iterations
  5. Train the model using gradient descent algorithm
  6. Test the accuracy of the model
  7. Visualize the best fit line using Matplotlib

Conclusion

Overall, this markdown file provides a basic understanding of how simple linear regression can be applied to a dataset using different libraries and methods.

About

This code does linear regression using scikit-learn and custom NumPy implementation. It loads datasets, removes NaNs, scales features, trains and evaluates models, and plots best fit line. Custom model uses gradient descent. Outputs R2 score, coefficients, and intercept.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published