mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Optimized recursive_bubble_sort (#2410)
* optimized recursive_bubble_sort * Fixed doctest error due whitespace * reduce loop times for optimization * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -135,8 +135,7 @@ class Decision_Tree:
|
||||
|
||||
|
||||
class Test_Decision_Tree:
|
||||
"""Decision Tres test class
|
||||
"""
|
||||
"""Decision Tres test class"""
|
||||
|
||||
@staticmethod
|
||||
def helper_mean_squared_error_test(labels, prediction):
|
||||
|
@ -132,12 +132,12 @@ def kmeans(
|
||||
data, k, initial_centroids, maxiter=500, record_heterogeneity=None, verbose=False
|
||||
):
|
||||
"""This function runs k-means on given data and initial set of centroids.
|
||||
maxiter: maximum number of iterations to run.(default=500)
|
||||
record_heterogeneity: (optional) a list, to store the history of heterogeneity
|
||||
as function of iterations
|
||||
if None, do not store the history.
|
||||
verbose: if True, print how many data points changed their cluster labels in
|
||||
each iteration"""
|
||||
maxiter: maximum number of iterations to run.(default=500)
|
||||
record_heterogeneity: (optional) a list, to store the history of heterogeneity
|
||||
as function of iterations
|
||||
if None, do not store the history.
|
||||
verbose: if True, print how many data points changed their cluster labels in
|
||||
each iteration"""
|
||||
centroids = initial_centroids[:]
|
||||
prev_cluster_assignment = None
|
||||
|
||||
|
@ -153,7 +153,7 @@ def calculate_variance(items: list, means: list, total_count: int) -> float:
|
||||
def predict_y_values(
|
||||
x_items: list, means: list, variance: float, probabilities: list
|
||||
) -> list:
|
||||
""" This function predicts new indexes(groups for our data)
|
||||
"""This function predicts new indexes(groups for our data)
|
||||
:param x_items: a list containing all items(gaussian distribution of all classes)
|
||||
:param means: a list containing real mean values of each class
|
||||
:param variance: calculated value of variance by calculate_variance function
|
||||
|
@ -12,7 +12,7 @@ import requests
|
||||
|
||||
|
||||
def collect_dataset():
|
||||
""" Collect dataset of CSGO
|
||||
"""Collect dataset of CSGO
|
||||
The dataset contains ADR vs Rating of a Player
|
||||
:return : dataset obtained from the link, as matrix
|
||||
"""
|
||||
@ -32,7 +32,7 @@ def collect_dataset():
|
||||
|
||||
|
||||
def run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta):
|
||||
""" Run steep gradient descent and updates the Feature vector accordingly_
|
||||
"""Run steep gradient descent and updates the Feature vector accordingly_
|
||||
:param data_x : contains the dataset
|
||||
:param data_y : contains the output associated with each data-entry
|
||||
:param len_data : length of the data_
|
||||
@ -51,7 +51,7 @@ def run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta):
|
||||
|
||||
|
||||
def sum_of_square_error(data_x, data_y, len_data, theta):
|
||||
""" Return sum of square error for error calculation
|
||||
"""Return sum of square error for error calculation
|
||||
:param data_x : contains our dataset
|
||||
:param data_y : contains the output (result vector)
|
||||
:param len_data : len of the dataset
|
||||
@ -66,7 +66,7 @@ def sum_of_square_error(data_x, data_y, len_data, theta):
|
||||
|
||||
|
||||
def run_linear_regression(data_x, data_y):
|
||||
""" Implement Linear regression over the dataset
|
||||
"""Implement Linear regression over the dataset
|
||||
:param data_x : contains our dataset
|
||||
:param data_y : contains the output (result vector)
|
||||
:return : feature for line of best fit (Feature vector)
|
||||
|
Reference in New Issue
Block a user