Coder Social home page Coder Social logo

abdel-matinou / clean-code-ml Goto Github PK

View Code? Open in Web Editor NEW

This project forked from davified/clean-code-ml

0.0 0.0 0.0 1.04 MB

:bathtub: Clean Code concepts adapted for machine learning and data science

License: Apache License 2.0

Python 1.54% Shell 0.36% Jupyter Notebook 98.10%

clean-code-ml's Introduction

clean-code-ml

Table of Contents

  • Introduction
  • Variables
    • Variable names should reveal intent
    • Use meaningful and pronounceable variable names
    • Use the same vocabulary for the same type of variable
    • Avoid magic numbers and magic strings
    • Use variables to keep code "DRY" ("Don't Repeat Yourself")
    • Use explanatory variables
    • Avoid mental mapping
    • Don't add unneeded context
  • Dispensables
    • Avoid comments
    • Remove dead code
    • Avoid print statements (even glorified print statements such as df.head(), df.describe(), df.plot())
  • Functions
    • Use functions to keep code "DRY"
    • Functions should do one thing
    • Functions should only be one level of abstraction
    • Function names should say what they do
    • Use type hints to improve readability
    • Avoid side effects
    • Avoid unexpected side effects on values passed as function parameters
    • Function arguments (2 or fewer ideally)
    • Use default arguments instead of short circuiting or conditionals
    • Don't use flags as function parameters
  • Design
    • Avoid exposing your internals (Keep implementation details hidden)

Introduction

Clean code practices (from Clean Code and Refactoring) adapted for machine learning / data science workflows in Python. This is not a style guide. It's a guide to producing readable, reusable, and refactorable software.

If you’ve tried your hand at machine learning or data science, you would know that code can get messy, quickly.

Unclean code adds to complexity by making code difficult to read and modify. As a consequence, changing code to respond to business needs becomes increasingly difficult, and sometimes even impossible. This has been written about extensively in several languages, and even in Python (e.g. Clean Code, Refactoring, clean-code-python). In this repo, we have adapted these principles for data science / machine learning codebases.

Targets Python3.7+

Inspired by clean-code-javascript and forked from clean-code-python.

Hands-on Exercise

If you'd like to try out these practices, we've created a refactoring exercise which you can follow along. Starting with a jupyter notebook with many code smells, you can apply these clean code principles and refactor it to be readable and maintainable. The sample final solution can be found in src/train.py.

clean-code-ml's People

Contributors

davidtan-tw avatar nhung121 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.