Package: ols-regressor
OLS_Regressor📌 AboutThe 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.💻 InstallationInstall the package from PyPiRun this command to install theols_regressorpackage from PyPipipinstallols_regressorInstall the package from GitHubRun the following commands to install from GitHub if the installation is unsuccessful from PyPi.Clone the repositoryOpen your terminal, navigate to where you would like the repository to be cloned and run the following command:$gitclonegit@github.com:UBC-MDS/OLS_regressor.gitCreate the conda environment and activate itRun the following command to create the conda environment which will include the necessary Python and Poetry versions and dependencies:condaenvcreate--nameols_regressorpython=3.9poetry==1.7.1-yNext, run the following command to activate the conda environment we created:condaactivate`ols_regressor`Install the package using PoetryRun the following command to install the packageols_regressor:poetryinstall💡 Functionsfit: 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.⭐ UsageThis 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 thevingettefor detailed usage.Importing the LinearRegressorfromOLS_Regressor.regressorimportLinearRegressorfromOls_regressor.cross_validateimportcross_validatefromsklearn.model_selectionimporttrain_test_splitfromsklearn.datasetsimportmake_regressionFitting the ModelTo 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 respectivelyregressor=LinearRegressor()regressor.fit(X,y)Making PredictionsOnce the model is trained, you can make predictions on new data:# Assuming X_new represents new datapredictions=regressor.predict(X_new)Evaluating the ModelTo 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 datar_squared=regressor.score(X_test,y_test)print(f"R-squared:{r_squared}")Cross-ValidationThe 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 LinearRegressormodel=LinearRegressor()# Performing cross-validationresults=cross_validate(model,X,y,cv=5)# cv is the number of folds# Printing the resultsprint("Cross-validation results:",results)🧪 Auto-testTo run the auto-test supported bypytest, simply run the following command in the terminal or commandline tools:pytesttests/✅OLS_Regressoruse in Python ecosystemThe 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 capabilitiesscikit-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.🤝 ContributorsXia Yimeng (@YimengXia)Sifan Zhang (@Sifanzzz)Charles Xu (@charlesxch)Waleed Mahmood (@WaleedMahmood1)🌏 ContributingInterested 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.📗 LicenseOLS_Regressoris licensed under the terms of the MIT license.👏 CreditsOLS_Regressorwas created withcookiecutterand thepy-pkgs-cookiecuttertemplate.🖇️ ReferencesGiriyewithana, N. (2023). Australian Vehicle Prices [Data set]. Kaggle.https://www.kaggle.com/datasets/nelgiriyewithana/australian-vehicle-pricesMichael, B. (2023, February 23). How Does Linear Regression Really Work. Towards Data Science.https://towardsdatascience.com/how-does-linear-regression-really-work-2387d0f11e8scikit-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 programshttps://pytest.org/