An Ordinary Least Square Regressor
Project description
OLS_Regressor
About
The OLS Regression Package is a Python library designed to streamline the process of performing Ordinary Least Squares (OLS) regression analysis. Whether you're a data scientist, researcher, or analyst, this package aims to provide a simple and efficient tool for fitting linear models to your data. It will fit a linear model with coefficients w = (w1, w2, ..., wn) to minimize Residual Sum of Squares (RSS) between the observed targets values in the dataset, and the targets predicted by the linear approximation for the examples in the dataset.
Installation
pip install ols_regressor
Functions
fit
: Fits the linear model according to the OLS mechanism.predict
: Predicts target values using the fitted linear model.score
: Calculates the coefficient of determination R-squared value for the prediction.cross_validate
: Performs cross-validated Ordinary Least Squares (OLS) regression.
Usage
This guide provides a quick start to using the OLS_Regressor package, specifically the LinearRegressor class, to perform linear regression analysis. The package offers simple-to-use methods for fitting the model, making predictions, and evaluating the performance. For more details about the package, please see the vingette for detailed usage.
Importing the LinearRegressor
from OLS_Regressor.regressor import LinearRegressor
from Ols_regressor.cross_validate import cross_validate
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_regression
Fitting the Model
To fit the linear regression model, you need to have your dataset ready, typically split into features (X) and the target variable (y). Here's how you can fit the model:
# Assuming X and y are your features and target variable respectively
regressor = LinearRegressor()
regressor.fit(X, y)
Making Predictions
Once the model is trained, you can make predictions on new data:
# Assuming X_new represents new data
predictions = regressor.predict(X_new)
Evaluating the Model
To evaluate the performance of your model, you can use the score method, which by default provides the R-squared value of the predictions:
# Evaluating the model on test data
r_squared = regressor.score(X_test, y_test)
print(f"R-squared: {r_squared}")
Cross-Validation
The OLS_Regressor package provides a cross_validate function to help evaluate the model's performance across different partitions of the dataset, ensuring a more robust assessment than using a single train-test split.
To use cross_validate, you must first import it from the package, then provide it with your dataset and the model you wish to evaluate. Here's an example:
# Creating an instance of LinearRegressor
model = LinearRegressor()
# Performing cross-validation
results = cross_validate(model, X, y, cv=5) # cv is the number of folds
# Printing the results
print("Cross-validation results:", results)
Auto-test
To run the auto-test supported by pytest
, simply run the following command in the terminal or commandline tools:
pytest test/
OLS_Regressor
use in Python ecosystem
The OLS Regression Package seamlessly integrates into the rich Python ecosystem, offering a specialized solution for Ordinary Least Squares (OLS) regression analysis. While various Python libraries provide general-purpose machine learning and statistical functionalities, our package focuses specifically on the simplicity and efficiency of linear regression. scikit-learn is a widely used machine learning library that encompasses regression among its many capabilities scikit-learn
. Our package distinguishes itself by providing a lightweight and user-friendly interface tailored for users seeking a straightforward solution for OLS regression without the overhead of extensive machine learning or statistical functionalities. If you find that your needs align more closely with a broader set of machine learning tools or comprehensive statistical modeling, scikit-learn or statsmodels may be suitable alternatives. As of [2024-01-12], no existing package caters specifically to OLS regression with our package's emphasis on simplicity and ease of use.
Contributors
- Xia Yimeng (@YimengXia)
- Sifan Zhang (@Sifanzzz)
- Charles Xu (@charlesxch)
- Waleed Mahmood (@WaleedMahmood1)
Contributing
Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.
License
OLS_Regressor
is licensed under the terms of the MIT license.
Credits
OLS_Regressor
was created with cookiecutter
and the py-pkgs-cookiecutter
template.
References
Giriyewithana, N. (2023). Australian Vehicle Prices [Data set]. Kaggle. https://www.kaggle.com/datasets/nelgiriyewithana/australian-vehicle-prices
Michael, B. (2023, February 23). How Does Linear Regression Really Work. Towards Data Science. https://towardsdatascience.com/how-does-linear-regression-really-work-2387d0f11e8
scikit-learn: Machine Learning in Python. https://scikit-learn.org/stable/
pandas: A Foundational Python Library for Data Analysis and Statistics. https://pandas.pydata.org/
pytest: helps you write better programs https://pytest.org/
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ols_regressor-0.4.3.tar.gz
.
File metadata
- Download URL: ols_regressor-0.4.3.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfa15a3b6466422a48c845bb68ca1bd5100e104d7c8bdad81bc5d765160dde0e |
|
MD5 | a2332f603ad8daf1da9c13d8be07ea20 |
|
BLAKE2b-256 | ad409fce7b36a08566382bf0ddf721396911d7319e201186e1ad018d1af609b6 |
File details
Details for the file ols_regressor-0.4.3-py3-none-any.whl
.
File metadata
- Download URL: ols_regressor-0.4.3-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 369e85e8a2723bf6f0d94deb47e60381c8d75531a7eefc2c13ee439766cbe995 |
|
MD5 | 473642735811f93ad428111a974a9b21 |
|
BLAKE2b-256 | 59bd3196890a1335e8cc9c9955031e6c7f1371b2f46c380dd66fd6d79e1dcfca |