Skip to content
Open
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
Binary file not shown.
11 changes: 7 additions & 4 deletions homemade/k_means/k_means.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ def centroids_find_closest(data, centroids):
# We need to return the following variables correctly.
closest_centroids_ids = np.zeros((num_examples, 1))

# Go over every example, find its closest centroid, and store
# the index inside closest_centroids_ids at the appropriate location.
# Concretely, closest_centroids_ids(i) should contain the index of the centroid
# closest to example i. Hence, it should be a value in the range 1...num_centroids.
"""
Go over every example, find its closest centroid, and store
the index inside closest_centroids_ids at the appropriate location.
Concretely, closest_centroids_ids(i) should contain the index of the centroid
closest to example i. Hence, it should be a value in the range 1...num_centroids.
"""

for example_index in range(num_examples):
distances = np.zeros((num_centroids, 1))
for centroid_index in range(num_centroids):
Expand Down
29 changes: 29 additions & 0 deletions homemade/k_means/k_means_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from k_means import KMeans
import pandas as pd

# Load data.
data = pd.read_csv('homemade-machine-learning\data\iris.csv')

# Get total number of Iris examples.
num_examples = data.shape[0]

# Get features.
x_train = data[['petal_length', 'petal_width']].values.reshape((num_examples, 2))

# Set K-Means parameters.

# Clusters act as the cassifications for our data.
num_clusters = 3

# Max number of iterations, acts as a stopping condition.
max_iterations = 50

# Load KMeans.
k_means = KMeans(x_train, num_clusters)

# Train / fit K-Means.
(centroids, closest_centroids_ids) = k_means.train(max_iterations)

print(centroids)

# There is no prediction module?
4 changes: 2 additions & 2 deletions homemade/linear_regression/linear_regression.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Linear Regression Module"""
#Linear Regression Module

# Import dependencies.
import numpy as np
from ..utils.features import prepare_for_training


class LinearRegression:
"""Linear Regression Class"""
#Linear Regression Class

def __init__(self, data, labels, polynomial_degree=0, sinusoid_degree=0):
"""Linear regression constructor.
Expand Down