Giter Club home page Giter Club logo

decision-tree-python's Introduction

decision-tree-python

Decision tree implementation from scratch in python.

Virtual environment

Creating:

conda create --name decision-tree python=3.8

Activating:

conda activate decision-tree

Installing packages:

pip install -r requirements.txt

Registrating the environment in a notebook

ipython kernel install --name "decision-tree" --user

Usage

IMPORTANT: only use numeric features for the X matrices.

Feel free to create a pull request with the additional implementation.

Classification tree

# Reading data
d = pd.read_csv("data/classification/train.csv")[['Age', 'Fare', 'Survived']].dropna()

# Constructing the X and Y matrices
X = d[['Age', 'Fare']]
Y = d['Survived'].values.tolist()

# Initiating the Node
root = Node(Y, X, max_depth=3, min_samples_split=100)

# Getting teh best split
root.grow_tree()

# Printing the tree information 
root.print_tree()

Regression tree

# Reading data
d = pd.read_csv("data/regression/auto-mpg.csv")

# Subsetting
d = d[d['horsepower']!='?']

# Constructing the X and Y matrices
features = ['horsepower', 'weight', 'acceleration']

for ft in features:
    d[ft] = pd.to_numeric(d[ft])

X = d[features]
Y = d['mpg'].values.tolist()

# Initiating the Node
root = NodeRegression(Y, X, max_depth=3, min_samples_split=3)

# Growing the tree
root.grow_tree()

# Printing tree 
root.print_tree()

decision-tree-python's People

Contributors

eligijus112 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.