repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/ldm/modules/diffusionmodules/util.py | ldm/modules/diffusionmodules/util.py | # adopted from
# https://github.com/openai/improved-diffusion/blob/main/improved_diffusion/gaussian_diffusion.py
# and
# https://github.com/lucidrains/denoising-diffusion-pytorch/blob/7706bdfc6f527f58d33f84b7b522e61e6e3164b3/denoising_diffusion_pytorch/denoising_diffusion_pytorch.py
# and
# https://github.com/openai/gu... | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | false |
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/ldm/modules/diffusionmodules/model.py | ldm/modules/diffusionmodules/model.py | # pytorch_diffusion + derived encoder decoder
import math
import torch
import torch.nn as nn
import numpy as np
from einops import rearrange
from typing import Optional, Any
from ldm.modules.attention import MemoryEfficientCrossAttention
try:
import xformers
import xformers.ops
XFORMERS_IS_AVAILBLE = True... | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | true |
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/ldm/modules/diffusionmodules/openaimodel.py | ldm/modules/diffusionmodules/openaimodel.py | from abc import abstractmethod
import math
import numpy as np
import torch as th
import torch.nn as nn
import torch.nn.functional as F
from ldm.modules.diffusionmodules.util import (
checkpoint,
conv_nd,
linear,
avg_pool_nd,
zero_module,
normalization,
timestep_embedding,
)
from ldm.module... | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | false |
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/ldm/modules/diffusionmodules/upscaling.py | ldm/modules/diffusionmodules/upscaling.py | import torch
import torch.nn as nn
import numpy as np
from functools import partial
from ldm.modules.diffusionmodules.util import extract_into_tensor, make_beta_schedule
from ldm.util import default
class AbstractLowScaleModel(nn.Module):
# for concatenating a downsampled image to the latent representation
d... | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | false |
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/ldm/modules/diffusionmodules/__init__.py | ldm/modules/diffusionmodules/__init__.py | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | false | |
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/ldm/data/util.py | ldm/data/util.py | import torch
from ldm.modules.midas.api import load_midas_transform
class AddMiDaS(object):
def __init__(self, model_type):
super().__init__()
self.transform = load_midas_transform(model_type)
def pt2np(self, x):
x = ((x + 1.0) * .5).detach().cpu().numpy()
return x
def n... | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | false |
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/ldm/data/__init__.py | ldm/data/__init__.py | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | false | |
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/cldm/hack.py | cldm/hack.py | import torch
import einops
import ldm.modules.encoders.modules
import ldm.modules.attention
from transformers import logging
from ldm.modules.attention import default
def disable_verbosity():
logging.set_verbosity_error()
print('logging improved.')
return
def enable_sliced_attention():
ldm.modules... | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | false |
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/cldm/ddim_hacked.py | cldm/ddim_hacked.py | """SAMPLING ONLY."""
import torch
import numpy as np
from tqdm import tqdm
from ldm.modules.diffusionmodules.util import make_ddim_sampling_parameters, make_ddim_timesteps, noise_like, extract_into_tensor
class DDIMSampler(object):
def __init__(self, model, schedule="linear", **kwargs):
super().__init__... | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | false |
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/cldm/model.py | cldm/model.py | import os
import torch
from omegaconf import OmegaConf
from ldm.util import instantiate_from_config
def get_state_dict(d):
return d.get('state_dict', d)
def load_state_dict(ckpt_path, location='cpu'):
_, extension = os.path.splitext(ckpt_path)
if extension.lower() == ".safetensors":
import safe... | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | false |
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/cldm/logger.py | cldm/logger.py | import os
import numpy as np
import torch
import torchvision
from PIL import Image
from pytorch_lightning.callbacks import Callback
from pytorch_lightning.utilities.distributed import rank_zero_only
class ImageLogger(Callback):
def __init__(self, batch_frequency=2000, max_images=4, clamp=True, increase_log_steps... | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | false |
lllyasviel/ControlNet | https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/cldm/cldm.py | cldm/cldm.py | import einops
import torch
import torch as th
import torch.nn as nn
from ldm.modules.diffusionmodules.util import (
conv_nd,
linear,
zero_module,
timestep_embedding,
)
from einops import rearrange, repeat
from torchvision.utils import make_grid
from ldm.modules.attention import SpatialTransformer
from... | python | Apache-2.0 | ed85cd1e25a5ed592f7d8178495b4483de0331bf | 2026-01-04T14:42:42.940079Z | false |
tatsu-lab/stanford_alpaca | https://github.com/tatsu-lab/stanford_alpaca/blob/761dc5bfbdeeffa89b8bff5d038781a4055f796a/train.py | train.py | # Copyright 2023 Rohan Taori, Ishaan Gulrajani, Tianyi Zhang, Yann Dubois, Xuechen Li
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LIC... | python | Apache-2.0 | 761dc5bfbdeeffa89b8bff5d038781a4055f796a | 2026-01-04T14:43:24.037119Z | false |
tatsu-lab/stanford_alpaca | https://github.com/tatsu-lab/stanford_alpaca/blob/761dc5bfbdeeffa89b8bff5d038781a4055f796a/weight_diff.py | weight_diff.py | # Copyright 2023 Rohan Taori, Ishaan Gulrajani, Tianyi Zhang, Yann Dubois, Xuechen Li
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LIC... | python | Apache-2.0 | 761dc5bfbdeeffa89b8bff5d038781a4055f796a | 2026-01-04T14:43:24.037119Z | false |
tatsu-lab/stanford_alpaca | https://github.com/tatsu-lab/stanford_alpaca/blob/761dc5bfbdeeffa89b8bff5d038781a4055f796a/generate_instruction.py | generate_instruction.py | """
batch_selfinstruct_generate.py
run:
python -m generate_instruction generate_instruction_following_data \
--output_dir ./ \
--num_instructions_to_generate 10 \
--model_name="text-davinci-003" \
"""
import time
import json
import os
import random
import re
import string
from functools import partial
from multi... | python | Apache-2.0 | 761dc5bfbdeeffa89b8bff5d038781a4055f796a | 2026-01-04T14:43:24.037119Z | false |
tatsu-lab/stanford_alpaca | https://github.com/tatsu-lab/stanford_alpaca/blob/761dc5bfbdeeffa89b8bff5d038781a4055f796a/utils.py | utils.py | import dataclasses
import logging
import math
import os
import io
import sys
import time
import json
from typing import Optional, Sequence, Union
import openai
import tqdm
from openai import openai_object
import copy
StrOrOpenAIObject = Union[str, openai_object.OpenAIObject]
openai_org = os.getenv("OPENAI_ORG")
if o... | python | Apache-2.0 | 761dc5bfbdeeffa89b8bff5d038781a4055f796a | 2026-01-04T14:43:24.037119Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/setup.py | setup.py | from setuptools import setup, find_packages
from codecs import open
from os import path
__version__ = '0.0.4'
here = path.abspath(path.dirname(__file__))
# get the dependencies and installs
with open(path.join(here, 'requirements.txt'), encoding='utf-8') as f:
all_reqs = f.read().split('\n')
install_requires = ... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/__init__.py | mlfromscratch/__init__.py | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false | |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/principal_component_analysis.py | mlfromscratch/unsupervised_learning/principal_component_analysis.py | from __future__ import print_function, division
import numpy as np
from mlfromscratch.utils import calculate_covariance_matrix
class PCA():
"""A method for doing dimensionality reduction by transforming the feature
space to a lower dimensionality, removing correlation between features and
maximizing the v... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/gaussian_mixture_model.py | mlfromscratch/unsupervised_learning/gaussian_mixture_model.py | from __future__ import division, print_function
import math
from sklearn import datasets
import numpy as np
from mlfromscratch.utils import normalize, euclidean_distance, calculate_covariance_matrix
from mlfromscratch.utils import Plot
class GaussianMixtureModel():
"""A probabilistic clustering method for determ... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/autoencoder.py | mlfromscratch/unsupervised_learning/autoencoder.py | from __future__ import print_function, division
from sklearn import datasets
import math
import matplotlib.pyplot as plt
import numpy as np
import progressbar
from sklearn.datasets import fetch_mldata
from mlfromscratch.deep_learning.optimizers import Adam
from mlfromscratch.deep_learning.loss_functions import CrossE... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/dcgan.py | mlfromscratch/unsupervised_learning/dcgan.py | from __future__ import print_function, division
import matplotlib.pyplot as plt
import numpy as np
import progressbar
from sklearn.datasets import fetch_mldata
from mlfromscratch.deep_learning.optimizers import Adam
from mlfromscratch.deep_learning.loss_functions import CrossEntropy
from mlfromscratch.deep_learning.la... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/restricted_boltzmann_machine.py | mlfromscratch/unsupervised_learning/restricted_boltzmann_machine.py | import logging
import numpy as np
import progressbar
from mlfromscratch.utils.misc import bar_widgets
from mlfromscratch.utils import batch_iterator
from mlfromscratch.deep_learning.activation_functions import Sigmoid
sigmoid = Sigmoid()
class RBM():
"""Bernoulli Restricted Boltzmann Machine (RBM)
Parameter... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/apriori.py | mlfromscratch/unsupervised_learning/apriori.py | from __future__ import division, print_function
import numpy as np
import itertools
class Rule():
def __init__(self, antecedent, concequent, confidence, support):
self.antecedent = antecedent
self.concequent = concequent
self.confidence = confidence
self.support = support
class A... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/generative_adversarial_network.py | mlfromscratch/unsupervised_learning/generative_adversarial_network.py | from __future__ import print_function, division
from sklearn import datasets
import math
import matplotlib.pyplot as plt
import numpy as np
import progressbar
from sklearn.datasets import fetch_mldata
from mlfromscratch.deep_learning.optimizers import Adam
from mlfromscratch.deep_learning.loss_functions import CrossE... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/dbscan.py | mlfromscratch/unsupervised_learning/dbscan.py | from __future__ import print_function, division
import numpy as np
from mlfromscratch.utils import Plot, euclidean_distance, normalize
class DBSCAN():
"""A density based clustering method that expands clusters from
samples that have more neighbors within a radius specified by eps
than the value min_sampl... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/k_means.py | mlfromscratch/unsupervised_learning/k_means.py | from __future__ import print_function, division
import numpy as np
from mlfromscratch.utils import normalize, euclidean_distance, Plot
from mlfromscratch.unsupervised_learning import *
class KMeans():
"""A simple clustering method that forms k clusters by iteratively reassigning
samples to the closest centroid... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/genetic_algorithm.py | mlfromscratch/unsupervised_learning/genetic_algorithm.py | from __future__ import print_function, division
import string
import numpy as np
class GeneticAlgorithm():
"""An implementation of a Genetic Algorithm which will try to produce the user
specified target string.
Parameters:
-----------
target_string: string
The string which the GA should tr... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/__init__.py | mlfromscratch/unsupervised_learning/__init__.py | from .principal_component_analysis import PCA
from .apriori import Apriori
from .dbscan import DBSCAN
from .fp_growth import FPGrowth
from .gaussian_mixture_model import GaussianMixtureModel
from .genetic_algorithm import GeneticAlgorithm
from .k_means import KMeans
from .partitioning_around_medoids import PAM
from .re... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/fp_growth.py | mlfromscratch/unsupervised_learning/fp_growth.py | from __future__ import division, print_function
import numpy as np
import itertools
class FPTreeNode():
def __init__(self, item=None, support=1):
# 'Value' of the item
self.item = item
# Number of times the item occurs in a
# transaction
self.support = support
# Chi... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/unsupervised_learning/partitioning_around_medoids.py | mlfromscratch/unsupervised_learning/partitioning_around_medoids.py | from __future__ import print_function, division
import numpy as np
from mlfromscratch.utils import normalize, euclidean_distance, Plot
from mlfromscratch.unsupervised_learning import PCA
class PAM():
"""A simple clustering method that forms k clusters by first assigning
samples to the closest medoids, and the... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/logistic_regression.py | mlfromscratch/supervised_learning/logistic_regression.py | from __future__ import print_function, division
import numpy as np
import math
from mlfromscratch.utils import make_diagonal, Plot
from mlfromscratch.deep_learning.activation_functions import Sigmoid
class LogisticRegression():
""" Logistic Regression classifier.
Parameters:
-----------
learning_rate:... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/neuroevolution.py | mlfromscratch/supervised_learning/neuroevolution.py | from __future__ import print_function, division
import numpy as np
import copy
class Neuroevolution():
""" Evolutionary optimization of Neural Networks.
Parameters:
-----------
n_individuals: int
The number of neural networks that are allowed in the population at a time.
mutation_rate: flo... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/k_nearest_neighbors.py | mlfromscratch/supervised_learning/k_nearest_neighbors.py | from __future__ import print_function, division
import numpy as np
from mlfromscratch.utils import euclidean_distance
class KNN():
""" K Nearest Neighbors classifier.
Parameters:
-----------
k: int
The number of closest neighbors that will determine the class of the
sample that we wis... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/regression.py | mlfromscratch/supervised_learning/regression.py | from __future__ import print_function, division
import numpy as np
import math
from mlfromscratch.utils import normalize, polynomial_features
class l1_regularization():
""" Regularization for Lasso Regression """
def __init__(self, alpha):
self.alpha = alpha
def __call__(self, w):
retu... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/multilayer_perceptron.py | mlfromscratch/supervised_learning/multilayer_perceptron.py | from __future__ import print_function, division
import numpy as np
import math
from sklearn import datasets
from mlfromscratch.utils import train_test_split, to_categorical, normalize, accuracy_score, Plot
from mlfromscratch.deep_learning.activation_functions import Sigmoid, Softmax
from mlfromscratch.deep_learning.lo... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/linear_discriminant_analysis.py | mlfromscratch/supervised_learning/linear_discriminant_analysis.py | from __future__ import print_function, division
import numpy as np
from mlfromscratch.utils import calculate_covariance_matrix, normalize, standardize
class LDA():
"""The Linear Discriminant Analysis classifier, also known as Fisher's linear discriminant.
Can besides from classification also be used to reduce ... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/bayesian_regression.py | mlfromscratch/supervised_learning/bayesian_regression.py | from __future__ import print_function, division
import numpy as np
from scipy.stats import chi2, multivariate_normal
from mlfromscratch.utils import mean_squared_error, train_test_split, polynomial_features
class BayesianRegression(object):
"""Bayesian regression model. If poly_degree is specified the features w... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/perceptron.py | mlfromscratch/supervised_learning/perceptron.py | from __future__ import print_function, division
import math
import numpy as np
# Import helper functions
from mlfromscratch.utils import train_test_split, to_categorical, normalize, accuracy_score
from mlfromscratch.deep_learning.activation_functions import Sigmoid, ReLU, SoftPlus, LeakyReLU, TanH, ELU
from mlfromscra... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/decision_tree.py | mlfromscratch/supervised_learning/decision_tree.py | from __future__ import division, print_function
import numpy as np
from mlfromscratch.utils import divide_on_feature, train_test_split, standardize, mean_squared_error
from mlfromscratch.utils import calculate_entropy, accuracy_score, calculate_variance
class DecisionNode():
"""Class that represents a decision no... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/multi_class_lda.py | mlfromscratch/supervised_learning/multi_class_lda.py | from __future__ import print_function, division
import matplotlib.pyplot as plt
import numpy as np
from mlfromscratch.utils import calculate_covariance_matrix, normalize, standardize
class MultiClassLDA():
"""Enables dimensionality reduction for multiple
class distributions. It transforms the features space i... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/__init__.py | mlfromscratch/supervised_learning/__init__.py | from .adaboost import Adaboost
from .bayesian_regression import BayesianRegression
from .decision_tree import RegressionTree, ClassificationTree, XGBoostRegressionTree
from .gradient_boosting import GradientBoostingClassifier, GradientBoostingRegressor
from .k_nearest_neighbors import KNN
from .linear_discriminant_anal... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/random_forest.py | mlfromscratch/supervised_learning/random_forest.py | from __future__ import division, print_function
import numpy as np
import math
import progressbar
# Import helper functions
from mlfromscratch.utils import divide_on_feature, train_test_split, get_random_subsets, normalize
from mlfromscratch.utils import accuracy_score, calculate_entropy
from mlfromscratch.unsupervise... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/gradient_boosting.py | mlfromscratch/supervised_learning/gradient_boosting.py | from __future__ import division, print_function
import numpy as np
import progressbar
# Import helper functions
from mlfromscratch.utils import train_test_split, standardize, to_categorical
from mlfromscratch.utils import mean_squared_error, accuracy_score
from mlfromscratch.deep_learning.loss_functions import SquareL... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/naive_bayes.py | mlfromscratch/supervised_learning/naive_bayes.py | from __future__ import division, print_function
import numpy as np
import math
from mlfromscratch.utils import train_test_split, normalize
from mlfromscratch.utils import Plot, accuracy_score
class NaiveBayes():
"""The Gaussian Naive Bayes classifier. """
def fit(self, X, y):
self.X, self.y = X, y
... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/support_vector_machine.py | mlfromscratch/supervised_learning/support_vector_machine.py |
from __future__ import division, print_function
import numpy as np
import cvxopt
from mlfromscratch.utils import train_test_split, normalize, accuracy_score
from mlfromscratch.utils.kernels import *
from mlfromscratch.utils import Plot
# Hide cvxopt output
cvxopt.solvers.options['show_progress'] = False
class Suppor... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/xgboost.py | mlfromscratch/supervised_learning/xgboost.py | from __future__ import division, print_function
import numpy as np
import progressbar
from mlfromscratch.utils import train_test_split, standardize, to_categorical, normalize
from mlfromscratch.utils import mean_squared_error, accuracy_score
from mlfromscratch.supervised_learning import XGBoostRegressionTree
from mlfr... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/adaboost.py | mlfromscratch/supervised_learning/adaboost.py | from __future__ import division, print_function
import numpy as np
import math
from sklearn import datasets
import matplotlib.pyplot as plt
import pandas as pd
# Import helper functions
from mlfromscratch.utils import train_test_split, accuracy_score, Plot
# Decision stump used as weak classifier in this impl. of Ada... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/particle_swarm_optimization.py | mlfromscratch/supervised_learning/particle_swarm_optimization.py | from __future__ import print_function, division
import numpy as np
import copy
class ParticleSwarmOptimizedNN():
""" Particle Swarm Optimization of Neural Network.
Parameters:
-----------
n_individuals: int
The number of neural networks that are allowed in the population at a time.
model_b... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/utils/misc.py | mlfromscratch/utils/misc.py | import progressbar
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib.cm as cmx
import matplotlib.colors as colors
import numpy as np
from mlfromscratch.utils.data_operation import calculate_covariance_matrix
from mlfromscratch.utils.data_operation import calculate_correlation_ma... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/utils/__init__.py | mlfromscratch/utils/__init__.py | from .misc import Plot
from .data_manipulation import *
from .data_operation import * | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/utils/data_operation.py | mlfromscratch/utils/data_operation.py | from __future__ import division
import numpy as np
import math
import sys
def calculate_entropy(y):
""" Calculate the entropy of label array y """
log2 = lambda x: math.log(x) / math.log(2)
unique_labels = np.unique(y)
entropy = 0
for label in unique_labels:
count = len(y[y == label])
... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/utils/kernels.py | mlfromscratch/utils/kernels.py | import numpy as np
def linear_kernel(**kwargs):
def f(x1, x2):
return np.inner(x1, x2)
return f
def polynomial_kernel(power, coef, **kwargs):
def f(x1, x2):
return (np.inner(x1, x2) + coef)**power
return f
def rbf_kernel(gamma, **kwargs):
def f(x1, x2):
distance = np.li... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/utils/data_manipulation.py | mlfromscratch/utils/data_manipulation.py | from __future__ import division
from itertools import combinations_with_replacement
import numpy as np
import math
import sys
def shuffle_data(X, y, seed=None):
""" Random shuffle of the samples in X and y """
if seed:
np.random.seed(seed)
idx = np.arange(X.shape[0])
np.random.shuffle(idx)
... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/principal_component_analysis.py | mlfromscratch/examples/principal_component_analysis.py | from sklearn import datasets
import matplotlib.pyplot as plt
import matplotlib.cm as cmx
import matplotlib.colors as colors
import numpy as np
from mlfromscratch.unsupervised_learning import PCA
def main():
# Demo of how to reduce the dimensionality of the data to two dimension
# and plot the results.
#... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/gaussian_mixture_model.py | mlfromscratch/examples/gaussian_mixture_model.py | from __future__ import division, print_function
import sys
import os
import math
import random
from sklearn import datasets
import numpy as np
from mlfromscratch.unsupervised_learning import GaussianMixtureModel
from mlfromscratch.utils import Plot
def main():
# Load the dataset
X, y = datasets.make_blobs()
... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/logistic_regression.py | mlfromscratch/examples/logistic_regression.py | from __future__ import print_function
from sklearn import datasets
import numpy as np
import matplotlib.pyplot as plt
# Import helper functions
from mlfromscratch.utils import make_diagonal, normalize, train_test_split, accuracy_score
from mlfromscratch.deep_learning.activation_functions import Sigmoid
from mlfromscra... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/neuroevolution.py | mlfromscratch/examples/neuroevolution.py |
from __future__ import print_function
from sklearn import datasets
import matplotlib.pyplot as plt
import numpy as np
from mlfromscratch.supervised_learning import Neuroevolution
from mlfromscratch.utils import train_test_split, to_categorical, normalize, Plot
from mlfromscratch.deep_learning import NeuralNetwork
fro... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/restricted_boltzmann_machine.py | mlfromscratch/examples/restricted_boltzmann_machine.py | import logging
import numpy as np
from sklearn import datasets
from sklearn.datasets import fetch_mldata
import matplotlib.pyplot as plt
from mlfromscratch.unsupervised_learning import RBM
logging.basicConfig(level=logging.DEBUG)
def main():
mnist = fetch_mldata('MNIST original')
X = mnist.data / 255.0
... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/apriori.py | mlfromscratch/examples/apriori.py | from __future__ import division, print_function
import numpy as np
from mlfromscratch.unsupervised_learning import Apriori
def main():
# Demo transaction set
# Example 2: https://en.wikipedia.org/wiki/Apriori_algorithm
transactions = np.array([[1, 2, 3, 4], [1, 2, 4], [1, 2], [2, 3, 4], [2, 3], [3, 4], [2... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/k_nearest_neighbors.py | mlfromscratch/examples/k_nearest_neighbors.py | from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from mlfromscratch.utils import train_test_split, normalize, accuracy_score
from mlfromscratch.utils import euclidean_distance, Plot
from mlfromscratch.supervised_learning import KNN
def main():
d... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/convolutional_neural_network.py | mlfromscratch/examples/convolutional_neural_network.py |
from __future__ import print_function
from sklearn import datasets
import matplotlib.pyplot as plt
import math
import numpy as np
# Import helper functions
from mlfromscratch.deep_learning import NeuralNetwork
from mlfromscratch.utils import train_test_split, to_categorical, normalize
from mlfromscratch.utils import ... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/deep_q_network.py | mlfromscratch/examples/deep_q_network.py | from __future__ import print_function
import numpy as np
from mlfromscratch.utils import to_categorical
from mlfromscratch.deep_learning.optimizers import Adam
from mlfromscratch.deep_learning.loss_functions import SquareLoss
from mlfromscratch.deep_learning.layers import Dense, Dropout, Flatten, Activation, Reshape, B... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/ridge_regression.py | mlfromscratch/examples/ridge_regression.py | from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# Import helper functions
from mlfromscratch.supervised_learning import PolynomialRidgeRegression
from mlfromscratch.utils import k_fold_cross_validation_sets, normalize, Plot
from mlfromscratch.utils import tra... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/multilayer_perceptron.py | mlfromscratch/examples/multilayer_perceptron.py |
from __future__ import print_function
from sklearn import datasets
import matplotlib.pyplot as plt
import numpy as np
# Import helper functions
from mlfromscratch.deep_learning import NeuralNetwork
from mlfromscratch.utils import train_test_split, to_categorical, normalize, Plot
from mlfromscratch.utils import get_ra... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/linear_discriminant_analysis.py | mlfromscratch/examples/linear_discriminant_analysis.py | from __future__ import print_function
from sklearn import datasets
import matplotlib.pyplot as plt
import numpy as np
from mlfromscratch.supervised_learning import LDA
from mlfromscratch.utils import calculate_covariance_matrix, accuracy_score
from mlfromscratch.utils import normalize, standardize, train_test_split, P... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/lasso_regression.py | mlfromscratch/examples/lasso_regression.py | from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# Import helper functions
from mlfromscratch.supervised_learning import LassoRegression
from mlfromscratch.utils import k_fold_cross_validation_sets, normalize, mean_squared_error
from mlfromscratch.utils import... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/decision_tree_classifier.py | mlfromscratch/examples/decision_tree_classifier.py | from __future__ import division, print_function
import numpy as np
from sklearn import datasets
import matplotlib.pyplot as plt
import sys
import os
# Import helper functions
from mlfromscratch.utils import train_test_split, standardize, accuracy_score
from mlfromscratch.utils import mean_squared_error, calculate_vari... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/bayesian_regression.py | mlfromscratch/examples/bayesian_regression.py | import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Import helper functions
from mlfromscratch.utils.data_operation import mean_squared_error
from mlfromscratch.utils.data_manipulation import train_test_split, polynomial_features
from mlfromscratch.supervised_learning import BayesianRegression
de... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/gradient_boosting_regressor.py | mlfromscratch/examples/gradient_boosting_regressor.py | from __future__ import division, print_function
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import progressbar
from mlfromscratch.utils import train_test_split, standardize, to_categorical
from mlfromscratch.utils import mean_squared_error, accuracy_score, Plot
from mlfromscratch.utils.loss_... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/perceptron.py | mlfromscratch/examples/perceptron.py | from __future__ import print_function
from sklearn import datasets
import numpy as np
# Import helper functions
from mlfromscratch.utils import train_test_split, normalize, to_categorical, accuracy_score
from mlfromscratch.deep_learning.activation_functions import Sigmoid
from mlfromscratch.deep_learning.loss_function... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/gradient_boosting_classifier.py | mlfromscratch/examples/gradient_boosting_classifier.py | from __future__ import division, print_function
import numpy as np
from sklearn import datasets
import matplotlib.pyplot as plt
# Import helper functions
from mlfromscratch.utils import train_test_split, accuracy_score
from mlfromscratch.deep_learning.loss_functions import CrossEntropy
from mlfromscratch.utils import ... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/dbscan.py | mlfromscratch/examples/dbscan.py | import sys
import os
import math
import random
from sklearn import datasets
import numpy as np
# Import helper functions
from mlfromscratch.utils import Plot
from mlfromscratch.unsupervised_learning import DBSCAN
def main():
# Load the dataset
X, y = datasets.make_moons(n_samples=300, noise=0.08, shuffle=Fals... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/demo.py | mlfromscratch/examples/demo.py | from __future__ import print_function
from sklearn import datasets
import numpy as np
import math
import matplotlib.pyplot as plt
from mlfromscratch.utils import train_test_split, normalize, to_categorical, accuracy_score
from mlfromscratch.deep_learning.optimizers import Adam
from mlfromscratch.deep_learning.loss_fun... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/k_means.py | mlfromscratch/examples/k_means.py | from __future__ import division, print_function
from sklearn import datasets
import numpy as np
from mlfromscratch.unsupervised_learning import KMeans
from mlfromscratch.utils import Plot
def main():
# Load the dataset
X, y = datasets.make_blobs()
# Cluster the data using K-Means
clf = KMeans(k=3)
... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/multi_class_lda.py | mlfromscratch/examples/multi_class_lda.py | from __future__ import print_function
from sklearn import datasets
import numpy as np
from mlfromscratch.supervised_learning import MultiClassLDA
from mlfromscratch.utils import normalize
def main():
# Load the dataset
data = datasets.load_iris()
X = normalize(data.data)
y = data.target
# Project... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/decision_tree_regressor.py | mlfromscratch/examples/decision_tree_regressor.py | from __future__ import division, print_function
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from mlfromscratch.utils import train_test_split, standardize, accuracy_score
from mlfromscratch.utils import mean_squared_error, calculate_variance, Plot
from mlfromscratch.supervised_learning import... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/genetic_algorithm.py | mlfromscratch/examples/genetic_algorithm.py |
from mlfromscratch.unsupervised_learning import GeneticAlgorithm
def main():
target_string = "Genetic Algorithm"
population_size = 100
mutation_rate = 0.05
genetic_algorithm = GeneticAlgorithm(target_string,
population_size,
... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/recurrent_neural_network.py | mlfromscratch/examples/recurrent_neural_network.py | from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
from mlfromscratch.deep_learning import NeuralNetwork
from mlfromscratch.utils import train_test_split, to_categorical, normalize, Plot
from mlfromscratch.utils import get_random_subsets, shuffle_data, accuracy_score
from mlfromsc... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/random_forest.py | mlfromscratch/examples/random_forest.py | from __future__ import division, print_function
import numpy as np
from sklearn import datasets
from mlfromscratch.utils import train_test_split, accuracy_score, Plot
from mlfromscratch.supervised_learning import RandomForest
def main():
data = datasets.load_digits()
X = data.data
y = data.target
X_tr... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/elastic_net.py | mlfromscratch/examples/elastic_net.py | from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# Import helper functions
from mlfromscratch.supervised_learning import ElasticNet
from mlfromscratch.utils import k_fold_cross_validation_sets, normalize, mean_squared_error
from mlfromscratch.utils import trai... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/naive_bayes.py | mlfromscratch/examples/naive_bayes.py | from __future__ import division, print_function
from sklearn import datasets
import numpy as np
from mlfromscratch.utils import train_test_split, normalize, accuracy_score, Plot
from mlfromscratch.supervised_learning import NaiveBayes
def main():
data = datasets.load_digits()
X = normalize(data.data)
y = d... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/fp_growth.py | mlfromscratch/examples/fp_growth.py |
import numpy as np
from mlfromscratch.unsupervised_learning import FPGrowth
def main():
# Demo transaction set
# Example:
# https://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Frequent_Pattern_Mining/The_FP-Growth_Algorithm
transactions = np.array([
["A", "B", "D", "E"],
["B... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/support_vector_machine.py | mlfromscratch/examples/support_vector_machine.py | from __future__ import division, print_function
import numpy as np
from sklearn import datasets
# Import helper functions
from mlfromscratch.utils import train_test_split, normalize, accuracy_score, Plot
from mlfromscratch.utils.kernels import *
from mlfromscratch.supervised_learning import SupportVectorMachine
def m... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/xgboost.py | mlfromscratch/examples/xgboost.py | from __future__ import division, print_function
import numpy as np
from sklearn import datasets
import matplotlib.pyplot as plt
import progressbar
from mlfromscratch.utils import train_test_split, standardize, to_categorical, normalize
from mlfromscratch.utils import mean_squared_error, accuracy_score, Plot
from mlfrom... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/polynomial_regression.py | mlfromscratch/examples/polynomial_regression.py | from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# Import helper functions
from mlfromscratch.supervised_learning import PolynomialRidgeRegression
from mlfromscratch.utils import k_fold_cross_validation_sets, normalize, mean_squared_error
from mlfromscratch.ut... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/partitioning_around_medoids.py | mlfromscratch/examples/partitioning_around_medoids.py | from sklearn import datasets
import numpy as np
# Import helper functions
from mlfromscratch.utils import Plot
from mlfromscratch.unsupervised_learning import PAM
def main():
# Load the dataset
X, y = datasets.make_blobs()
# Cluster the data using K-Medoids
clf = PAM(k=3)
y_pred = clf.predict(X)
... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/adaboost.py | mlfromscratch/examples/adaboost.py | from __future__ import division, print_function
import numpy as np
from sklearn import datasets
# Import helper functions
from mlfromscratch.supervised_learning import Adaboost
from mlfromscratch.utils.data_manipulation import train_test_split
from mlfromscratch.utils.data_operation import accuracy_score
from mlfromsc... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/linear_regression.py | mlfromscratch/examples/linear_regression.py | import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.datasets import make_regression
from mlfromscratch.utils import train_test_split, polynomial_features
from mlfromscratch.utils import mean_squared_error, Plot
from mlfromscratch.supervised_learning import LinearRegression
def main():
... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/examples/particle_swarm_optimization.py | mlfromscratch/examples/particle_swarm_optimization.py |
from __future__ import print_function
from sklearn import datasets
import matplotlib.pyplot as plt
import numpy as np
from mlfromscratch.supervised_learning import ParticleSwarmOptimizedNN
from mlfromscratch.utils import train_test_split, to_categorical, normalize, Plot
from mlfromscratch.deep_learning import NeuralN... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/deep_learning/loss_functions.py | mlfromscratch/deep_learning/loss_functions.py | from __future__ import division
import numpy as np
from mlfromscratch.utils import accuracy_score
from mlfromscratch.deep_learning.activation_functions import Sigmoid
class Loss(object):
def loss(self, y_true, y_pred):
return NotImplementedError()
def gradient(self, y, y_pred):
raise NotImplem... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/deep_learning/neural_network.py | mlfromscratch/deep_learning/neural_network.py | from __future__ import print_function, division
from terminaltables import AsciiTable
import numpy as np
import progressbar
from mlfromscratch.utils import batch_iterator
from mlfromscratch.utils.misc import bar_widgets
class NeuralNetwork():
"""Neural Network. Deep Learning base model.
Parameters:
-----... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/deep_learning/optimizers.py | mlfromscratch/deep_learning/optimizers.py | import numpy as np
from mlfromscratch.utils import make_diagonal, normalize
# Optimizers for models that use gradient based methods for finding the
# weights that minimizes the loss.
# A great resource for understanding these methods:
# http://sebastianruder.com/optimizing-gradient-descent/index.html
class Stochast... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/deep_learning/__init__.py | mlfromscratch/deep_learning/__init__.py | from .neural_network import NeuralNetwork
| python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/deep_learning/activation_functions.py | mlfromscratch/deep_learning/activation_functions.py | import numpy as np
# Collection of activation functions
# Reference: https://en.wikipedia.org/wiki/Activation_function
class Sigmoid():
def __call__(self, x):
return 1 / (1 + np.exp(-x))
def gradient(self, x):
return self.__call__(x) * (1 - self.__call__(x))
class Softmax():
def __call__... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/deep_learning/layers.py | mlfromscratch/deep_learning/layers.py |
from __future__ import print_function, division
import math
import numpy as np
import copy
from mlfromscratch.deep_learning.activation_functions import Sigmoid, ReLU, SoftPlus, LeakyReLU
from mlfromscratch.deep_learning.activation_functions import TanH, ELU, SELU, Softmax
class Layer(object):
def set_input_shap... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/reinforcement_learning/deep_q_network.py | mlfromscratch/reinforcement_learning/deep_q_network.py | from __future__ import print_function, division
import random
import numpy as np
import gym
from collections import deque
class DeepQNetwork():
"""Q-Learning with deep neural network to learn the control policy.
Uses a deep neural network model to predict the expected utility (Q-value) of executing an action... | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
eriklindernoren/ML-From-Scratch | https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/reinforcement_learning/__init__.py | mlfromscratch/reinforcement_learning/__init__.py | from .deep_q_network import DeepQNetwork | python | MIT | a2806c6732eee8d27762edd6d864e0c179d8e9e8 | 2026-01-04T14:43:27.007398Z | false |
commaai/openpilot | https://github.com/commaai/openpilot/blob/adbf68f77120b4568de68c37b8bed4ed433e01fe/conftest.py | conftest.py | import contextlib
import gc
import os
import pytest
from openpilot.common.prefix import OpenpilotPrefix
from openpilot.system.manager import manager
from openpilot.system.hardware import TICI, HARDWARE
# TODO: pytest-cpp doesn't support FAIL, and we need to create test translations in sessionstart
# pending https://g... | python | MIT | adbf68f77120b4568de68c37b8bed4ed433e01fe | 2026-01-04T14:38:40.093933Z | false |
commaai/openpilot | https://github.com/commaai/openpilot/blob/adbf68f77120b4568de68c37b8bed4ed433e01fe/third_party/acados/acados_template/zoro_description.py | third_party/acados/acados_template/zoro_description.py | # Copyright (c) The acados authors.
#
# This file is part of acados.
#
# The 2-Clause BSD License
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright not... | python | MIT | adbf68f77120b4568de68c37b8bed4ed433e01fe | 2026-01-04T14:38:40.093933Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.