Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a downloads badge to the README #29

Merged
merged 3 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/ambv/black
rev: 19.3b0
rev: 22.6.0
hooks:
- id: black
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.3.0
hooks:
- id: check-yaml
- id: check-toml
Expand All @@ -16,7 +16,7 @@ repos:
args:
- --maxkb=1000
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.10
rev: v1.3.0
hooks:
- id: remove-crlf
- id: remove-tabs
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Deploy](https://github.com/hasnainroopawalla/ShowML/actions/workflows/deploy.yml/badge.svg)](https://github.com/hasnainroopawalla/ShowML/actions/workflows/deploy.yml)
[![PyPi version](https://img.shields.io/pypi/v/showml.svg)](https://pypi.python.org/pypi/showml/)
[![Python versions](https://img.shields.io/pypi/pyversions/showml.svg?style=plastic)](https://img.shields.io/pypi/pyversions/showml.svg?style=plastic)
![Status](https://img.shields.io/badge/status-stable-green.svg)
![Downloads](https://img.shields.io/pypi/dm/showml.svg)


A Python package of Machine Learning Algorithms implemented from scratch.
Expand All @@ -23,6 +23,7 @@ The aim of this package is to present the working behind fundamental Machine Lea
- [Getting Started](#getting_started)
- [Contents](#contents)
- [Contributing](#contributing)
- [License](#license)


## 🏁 Getting Started <a name = "getting_started"></a>
Expand Down Expand Up @@ -104,3 +105,7 @@ _ShowML_ currently includes the following content, however, this repository will
$ pytest
```
5. Open a Pull Request and I'll review it.


## 📄 License <a name = "license"></a>
This project is licensed under the MIT License - see the [LICENSE](https://github.com/hasnainroopawalla/ShowML/blob/bbaacc81779437ea2ef09d7869b1f8a824f80353/LICENSE) file for details.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name="showml",
version="1.5.11",
version="1.5.12",
packages=find_packages(exclude="tests"),
description="A Python package of Machine Learning Algorithms implemented from scratch",
long_description=long_description,
Expand Down
9 changes: 3 additions & 6 deletions showml/deep_learning/activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@


class Sigmoid(Activation):
"""A layer which applies the Sigmoid operation to an input.
"""
"""A layer which applies the Sigmoid operation to an input."""

def forward(self, X: np.ndarray) -> np.ndarray:
return 1 / (1 + np.exp(-X))
Expand All @@ -14,8 +13,7 @@ def backward(self, X: np.ndarray) -> np.ndarray:


class Relu(Activation):
"""A layer which applies the ReLU operation to an input.
"""
"""A layer which applies the ReLU operation to an input."""

def forward(self, X: np.ndarray) -> np.ndarray:
return abs(X) * (X > 0)
Expand All @@ -25,8 +23,7 @@ def backward(self, X: np.ndarray) -> np.ndarray:


class Softmax(Activation):
"""A layer which applies the Softmax operation to an input.
"""
"""A layer which applies the Softmax operation to an input."""

def forward(self, X: np.ndarray) -> np.ndarray:
e_x = np.exp(X - np.max(X, axis=-1, keepdims=True))
Expand Down
3 changes: 1 addition & 2 deletions showml/deep_learning/base_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@


class Layer(ABC):
"""A layer class.
"""
"""A layer class."""

def __init__(
self, input_shape: Tuple[int] = (0,), has_weights: bool = True
Expand Down
5 changes: 2 additions & 3 deletions showml/deep_learning/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@


class Dense(Layer):
"""A Dense Layer.
"""
"""A Dense Layer."""

def __init__(self, num_nodes: int, input_shape: Tuple[int] = (0,)):
"""Constructor for the Dense Layer.
Expand All @@ -27,7 +26,7 @@ def initialize_params(self, optimizer: Optimizer) -> None:
self.bias = np.zeros((1, self.num_nodes))

def get_params_count(self) -> int:
return np.prod(self.weights.shape) + np.prod(self.bias.shape)
return int(np.prod(self.weights.shape) + np.prod(self.bias.shape))

def get_output_shape(self) -> Tuple[int]:
return (self.num_nodes,)
Expand Down
12 changes: 4 additions & 8 deletions showml/deep_learning/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@


class Sequential:
"""A Sequential model (deep neural network) with various types of layers and activation functions.
"""
"""A Sequential model (deep neural network) with various types of layers and activation functions."""

def __init__(self) -> None:
"""Constructor for the Sequential model class.
"""
"""Constructor for the Sequential model class."""
self.layers: List[Layer] = []

def compile(
Expand All @@ -39,8 +37,7 @@ def compile(
self.initialize_layers()

def initialize_layers(self) -> None:
"""Initializes all the layers with the specified optimizer and parameters.
"""
"""Initializes all the layers with the specified optimizer and parameters."""
for layer_idx, layer in enumerate(self.layers):
if layer_idx > 0:
# If this layer is NOT the first layer of the network, then input shape = output shape of previous layer
Expand Down Expand Up @@ -132,8 +129,7 @@ def predict(self, X: np.ndarray) -> np.ndarray:
return self.forward_pass(X)

def summary(self) -> None:
"""Summarizes the model by displaying all layers, their parameters and total number of trainable parameters.
"""
"""Summarizes the model by displaying all layers, their parameters and total number of trainable parameters."""
total_params = 0
print(AsciiTable([[self.__class__.__name__]]).table)
summary_data = [["Layer", "Params", "Output Shape"]]
Expand Down
6 changes: 2 additions & 4 deletions showml/linear_model/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@


class Regression(ABC):
"""Base Regression class.
"""
"""Base Regression class."""

def compile(
self, optimizer: Optimizer, loss: Loss, metrics: List[Callable] = []
Expand Down Expand Up @@ -62,8 +61,7 @@ def evaluate(self, X: np.ndarray, y: np.ndarray) -> None:
print(text_to_display)

def plot_metrics(self) -> None:
"""Display the plot after training for the specified metrics
"""
"""Display the plot after training for the specified metrics"""
for metric in self.history:
generic_metric_plot(metric, self.history[metric])

Expand Down
6 changes: 2 additions & 4 deletions showml/losses/loss_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def parameter_gradient(

class BinaryCrossEntropy(Loss):
def objective(self, y: np.ndarray, z: np.ndarray) -> float:
"""Also known as Log Loss
"""
"""Also known as Log Loss"""
num_samples = len(y)
# Avoid division by zero
z = np.clip(z, 1e-15, 1 - 1e-15)
Expand All @@ -46,8 +45,7 @@ def parameter_gradient(

class CrossEntropy(Loss):
def objective(self, y: np.ndarray, z: np.ndarray) -> float:
"""param y: one hot encoded values
"""
"""param y: one hot encoded values"""
num_samples = len(z)
z = np.clip(z, 1e-15, 1.0 - 1e-15)
return -np.sum(y * np.log(z)) / num_samples
Expand Down
3 changes: 1 addition & 2 deletions showml/optimizers/base_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


class Optimizer(ABC):
"""The Base Optimizer Class.
"""
"""The Base Optimizer Class."""

def __init__(self, learning_rate: float):
"""Constructor for the Base Optimzer class.
Expand Down
6 changes: 2 additions & 4 deletions showml/simulations/conways_game_of_life/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@


class Action(Enum):
"""This class defines the different Actions in the game.
"""
"""This class defines the different Actions in the game."""

START = auto()
STOP = auto()
Expand All @@ -15,8 +14,7 @@ class Action(Enum):

@dataclass
class Event:
"""This class defines an Event (and also the row, column if a cell is toggled)
"""
"""This class defines an Event (and also the row, column if a cell is toggled)"""

action: Action
row: int = 0
Expand Down
3 changes: 1 addition & 2 deletions showml/simulations/conways_game_of_life/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


class EventHandler:
"""The EventHandler class responsible for observing events taking place in the window as well as initializing and managing the Grid.
"""
"""The EventHandler class responsible for observing events taking place in the window as well as initializing and managing the Grid."""

def __init__(self, window: GameWindow) -> None:
"""Constructor for the EventHandler class.
Expand Down
15 changes: 5 additions & 10 deletions showml/simulations/conways_game_of_life/game_of_life.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@


class GameOfLife:
"""A simulation of Conway's Game of Life (Cellular Automaton): https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
"""
"""A simulation of Conway's Game of Life (Cellular Automaton): https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life"""

def __init__(self, num_rows: int = 50, num_columns: int = 100) -> None:
"""Constructor for the GameOfLife class.
Expand All @@ -28,20 +27,17 @@ def __init__(self, num_rows: int = 50, num_columns: int = 100) -> None:
}

def start_event(self, row: int, column: int) -> None:
"""This method runs when the game starts.
"""
"""This method runs when the game starts."""
self.game_running = True
self.delay = 150

def stop_event(self, row: int, column: int) -> None:
"""This method runs when the game is stopped.
"""
"""This method runs when the game is stopped."""
self.game_running = False
self.delay = 0

def reset_event(self, row: int, column: int) -> None:
"""This method runs when the RESET button is pressed.
"""
"""This method runs when the RESET button is pressed."""
self.game_running = False
self.window.grid.reset_grid()
self.delay = 0
Expand All @@ -59,8 +55,7 @@ def no_event(self, row: int, column: int) -> None:
pass

def run(self) -> None:
"""This method runs the game loop by communicating with the EventHandler to receive event information.
"""
"""This method runs the game loop by communicating with the EventHandler to receive event information."""
while True:
if self.game_running:
self.window.grid.update_grid()
Expand Down
9 changes: 3 additions & 6 deletions showml/simulations/conways_game_of_life/game_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@


class GameWindow:
"""The GameWindow class responsible for observing events taking place in the window as well as initializing and managing the Grid.
"""
"""The GameWindow class responsible for observing events taking place in the window as well as initializing and managing the Grid."""

def __init__(self, grid: Grid) -> None:
"""Constructor for the GameWindow class.
Expand Down Expand Up @@ -55,8 +54,7 @@ def display_window_and_grid(self, delay: int) -> None:
self.clock.tick(60)

def _display_buttons_and_text(self) -> None:
"""This private method displays the buttons and the text objects in the window.
"""
"""This private method displays the buttons and the text objects in the window."""
self.SCREEN.fill(Color.BLACK)
for button in self.buttons:
# Button
Expand All @@ -75,8 +73,7 @@ def _display_buttons_and_text(self) -> None:
)

def _display_grid(self) -> None:
"""This private method displays the entire grid in the window.
"""
"""This private method displays the entire grid in the window."""
for row in range(self.grid.num_rows):
for column in range(self.grid.num_columns):
if self.grid.grid[row][column] == 1:
Expand Down
6 changes: 2 additions & 4 deletions showml/simulations/conways_game_of_life/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@


class Grid:
"""A 2D Grid class to display the cells.
"""
"""A 2D Grid class to display the cells."""

def __init__(self, num_rows: int, num_columns: int) -> None:
"""[summary]
Expand Down Expand Up @@ -60,8 +59,7 @@ def update_grid(self) -> None:
self.grid = new_grid

def reset_grid(self) -> None:
"""This method resets the grid i.e., kills all the cells.
"""
"""This method resets the grid i.e., kills all the cells."""
self.grid = np.zeros((self.num_rows, self.num_columns))

def toggle_cell_value(self, row: int, column: int) -> None:
Expand Down
6 changes: 2 additions & 4 deletions showml/utils/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ def __init__(self, X: np.ndarray, y: np.ndarray) -> None:
self.valid_dataset_length()

def validate_data_types(self) -> None:
"""Validates if X and y are NumPy arrays (np.ndarray).
"""
"""Validates if X and y are NumPy arrays (np.ndarray)."""
if not (isinstance(self.X, np.ndarray) and isinstance(self.y, np.ndarray)):
raise DataTypeError("X and y must be NumPy arrays (np.ndarray)")

def valid_dataset_length(self) -> None:
"""Validates if X and y have the same number of samples.
"""
"""Validates if X and y have the same number of samples."""
if self.X.shape[0] != self.y.shape[0]:
raise DatasetSizeMismatchError(
"Dimension 1 (number of samples) of X and y must the same"
Expand Down
12 changes: 4 additions & 8 deletions showml/utils/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
class DatasetSizeMismatchError(Exception):
"""Raised when X and y have different lengths.
"""
"""Raised when X and y have different lengths."""


class DataTypeError(Exception):
"""Raised when a variable has an unexpected datatype.
"""
"""Raised when a variable has an unexpected datatype."""


class InvalidShapeError(Exception):
"""Raised when an unexpected array shape is encountered.
"""
"""Raised when an unexpected array shape is encountered."""


class InvalidValueError(Exception):
"""Raised when an unexpected value is encountered.
"""
"""Raised when an unexpected value is encountered."""