Git Product home page Git Product logo

davidcico / self-implementation-of-a-random-forest-algorithm Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 2.0 97 KB

A random forest algorithm is implemented in Python from scratch to perform a classification analysis.

Python 50.73% Jupyter Notebook 49.27%
jupyter-notebook machine-learning algorithm machine-learning-algorithms scratch scratch-implementation random-forest classification-task classification-trees python python3

self-implementation-of-a-random-forest-algorithm's Introduction

Self-implementation-of-a-random-forest-algorithm

The current repository contains different scripts, in which functions are implemented in Python from scratch, to carry out a classification problem using a random forest algorithm.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

You need Python 3.x to run the following code. You can have multiple Python versions (2.x and 3.x) installed on the same system without problems.

In Ubuntu, Mint and Debian you can install Python 3 like this:

sudo apt-get install python3 python3-pip

The Jupyter Notebook which can be installed through Python's package manager:

pip3 install --upgrade pip
pip3 install jupyter

For other Linux flavors, OS X and Windows:

Python is available at http://www.python.org/getit/
Jupyter Notebook at https://jupyter.readthedocs.io/en/latest/install.html

File descriptions

  • The files "sonar-all-data.csv" and "wheat_seeds.csv" correspond to the dataset used in the notebook.
  • "Open_conversion_data.py" contains all initial operations to be done to read the data from a CSV file, modify the variable types in the different columns (features) of the dataset, as well as data re-scaling, such as normalization and standardization. For more information on the different operations, the reader is referred to the Jupyter notebook Open_conversion_data.ipynb where the different functions are more elaborated.

  • In "Algorithm_test_harness.py" 2 approaches to split a dataset are implemented, to understand how the split between training and testing occur for machine learning problems. The main algorithm procedure based on the data split is also implemented, to evaluate the performances of a particular model.

  • "Performance_assessment.py" is a Python script in which accuracy metrics to measure machine learning algorithms performance are introduced, and implemented in a simple way. The Jupyter notebook Performance_assessment.ipynb is available for more details.

  • "Tree_model_RF.py" is the Python implementation of the Random Forest (RF) model for a classification problem, and following a Classification And Regression Trees (CART) approach.

  • "Sonar_case_study.py" is the main Python script, calling the different functions from the scripts above, to perform a classification analysis of the sonar case, with the implemented random forest model. To change to the wheat seeds dataset, the user just needs to change the file in the load_csv function call.

  • "Sonar_case_study.ipynb" is the Jupyter notebook version of the ".py" script.

  • "Random_Forest_from_scratch.pdf" is the pdf file with explanation on the different steps required to implement from zero, a RF model, with application on the sonar dataset.

Running the files

The different ".py" files need to be placed in the same folder for the main script to be run. The code is then ready to be used on the wheat seeds dataset and just requires running the following command:

python Sonar_case_study.py

The notebook can be directly opened on GitHub. An alternative way to open the notebooks, is to run the Jupyter Notebook. This can be done by executing the following command at the Terminal (Mac/Linux) or Command Prompt (Windows):

jupyter notebook

This will print some information about the notebook server in your terminal, including the URL of the web application (by default, http://localhost:8888):

$ jupyter notebook
[I 11:47:00.830 NotebookApp] Serving notebooks from local directory: C:\Users\EC-PM-3
[I 11:47:00.830 NotebookApp] The Jupyter Notebook is running at:
[I 11:47:00.830 NotebookApp] http://localhost:8888/?token=d22181d47f4826316a37161bb8c8469d77a5851bf9ab2c1f
[I 11:47:00.830 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

It will then open your default web browser to this URL.

When the notebook opens in your browser, you will see the Notebook Dashboard, which will show a list of the notebooks, files, and subdirectories in the directory where the notebook server was started. The notebook can then be chosen by navigating in the Notebook Dashboard.

For more information on how to run a specific jupyter notebook, you can go to the following link.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

self-implementation-of-a-random-forest-algorithm's People

Contributors

davidcico avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ameenali 5l1v3r1

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.