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 details)

Uploaded Source

File details

Details for the file linear_reg_youcef-1.0.0.tar.gz.

File metadata

  • Download URL: linear_reg_youcef-1.0.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.4

File hashes

Hashes for linear_reg_youcef-1.0.0.tar.gz
Algorithm Hash digest
SHA256 85048baae001555e66864a83c7821074289d699abfcf289940889c777c5d11c2
MD5 d232f408a69a6a37d8c9203c48ff42d5
BLAKE2b-256 3250d52d8ed80ed912a5bd4d689474d6ebe4a81d2c29bd832c53314e22f162a4

See more details on using hashes here.

Supported by

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