Giter Site home page Giter Site logo

pwc2 / ridge-regression Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 21.46 MB

Implementation of linear regression with L2 regularization (ridge regression) using numpy.

Python 100.00%
ridge-regression machine-learning l2-regularization batch-gradient-descent

ridge-regression's Introduction

ridge-regression

ridge-regression is an implementation of linear regression with L2 regularization that uses batch gradient descent to optimize weights.

Requirements:

  • numpy 1.17.2

  • pandas 0.25.1

  • progressbar2 3.37.1

Usage:

from models.linear_model import LinearModel

model = LinearModel(train='data/PA1_train.pkl', # Path to training set
                    validation='data/PA1_dev.pkl', # Path to validation set
                    test='data/PA1_test.pkl', # Path to test set
                    target='price', # Target for prediction
                    rate=1e-05, # Learning rate for gradient descent
                    lam=0, # Regularization penalty
                    eps=0.5, # Stopping condition for norm of gradient
                    normalize=True) # Indicate whether or not to normalize data

names = model.weight_labels # Extract labels for weights
learned_model = model.train_model(max_iter=10000) # Train model
val_predictions = model.predict_validation(learned_model['weights'])['predictions'] # Get predictions on validation set
test_predictions = model.predict_test((learned_model['weights']))['predictions'] # Get predictions on test set

Data:

The data/ folder contains .csv files with training, validation, and test sets.

To run models:

In run module:

  • run_part0.py takes care of cleaning training, validation, and test sets.

  • run_part1.py normalizes data to [0, 1] scale, and runs linear regression without L2 regularization penalty for various learning rates.

  • run_part2.py normalizes data to [0, 1] scale, runs linear regression with L2 regularization with fixed learning rate and various regularization penalties.

  • run_part3.py no normalization, runs linear regression without L2 regularization penalty for given learning rates.

Use python main.py to run all four parts.

ridge-regression's People

Contributors

pwc2 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.