Skip to main content

`linear_reg_youcef` is a Python library for predicting values based on linear regression concept

Project description

Linear Regression

This repository contains a simple implementation of a Linear Regression model using Python and NumPy.

Overview

The LinearRegression class implements a basic linear regression model with gradient descent optimization. The model can be trained on a dataset and used to make predictions.

Installation

To use this code, you need to have Python and NumPy installed. You can install NumPy using pip:

pip install numpy
pip install linear_reg_youcef

Usage

Importing the Module

First, import the necessary module:

import numpy as np
from linear_reg_youcef import LinearRegression

Creating the Model

Create an instance of the LinearRegression class by passing the input data (x) and the target labels (y):

x = np.array([1, 2, 3, 4, 5])
y = np.array([2, 4, 6, 8, 10])
model = LinearRegression(x, y)

Training the Model

Train the model using the fit method. You need to specify the number of epochs and the learning rate:

epochs = 1000
learning_rate = 0.01
model.fit(epochs, learning_rate)

Making Predictions

Use the predict method to make predictions on new data:

new_data = np.array([6, 7, 8])
predictions = model.predict(new_data)
print(predictions)

Code Explanation

LinearRegression Class

  • __init__(self, x, y): Initializes the model with input data x and target labels y. It also initializes the parameters m (slope) and b (intercept) to 0, and calculates the number of data points n.

  • fit(self, epochs, lr): Trains the model using gradient descent. It updates the parameters m and b over a specified number of epochs with a given learning rate lr.

  • predict(self, inp): Makes predictions on new input data inp using the trained model parameters.

License

MIT

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

linear_reg_youcef-1.0.0.tar.gz (3.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page