mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-10 06:10:33 +08:00
Wrap lines that go beyond GitHub Editor (#1925)
* Wrap lines that go beyond GiHub Editor * flake8 --count --select=E501 --max-line-length=127 * updating DIRECTORY.md * Update strassen_matrix_multiplication.py * fixup! Format Python code with psf/black push * Update decision_tree.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -20,15 +20,21 @@ class Decision_Tree:
|
||||
mean_squared_error:
|
||||
@param labels: a one dimensional numpy array
|
||||
@param prediction: a floating point value
|
||||
return value: mean_squared_error calculates the error if prediction is used to estimate the labels
|
||||
return value: mean_squared_error calculates the error if prediction is used to
|
||||
estimate the labels
|
||||
>>> tester = Decision_Tree()
|
||||
>>> test_labels = np.array([1,2,3,4,5,6,7,8,9,10])
|
||||
>>> test_prediction = np.float(6)
|
||||
>>> assert tester.mean_squared_error(test_labels, test_prediction) == Test_Decision_Tree.helper_mean_squared_error_test(test_labels, test_prediction)
|
||||
>>> tester.mean_squared_error(test_labels, test_prediction) == (
|
||||
... Test_Decision_Tree.helper_mean_squared_error_test(test_labels,
|
||||
... test_prediction))
|
||||
True
|
||||
>>> test_labels = np.array([1,2,3])
|
||||
>>> test_prediction = np.float(2)
|
||||
>>> assert tester.mean_squared_error(test_labels, test_prediction) == Test_Decision_Tree.helper_mean_squared_error_test(test_labels, test_prediction)
|
||||
|
||||
>>> tester.mean_squared_error(test_labels, test_prediction) == (
|
||||
... Test_Decision_Tree.helper_mean_squared_error_test(test_labels,
|
||||
... test_prediction))
|
||||
True
|
||||
"""
|
||||
if labels.ndim != 1:
|
||||
print("Error: Input labels must be one dimensional")
|
||||
@ -46,7 +52,8 @@ class Decision_Tree:
|
||||
"""
|
||||
|
||||
"""
|
||||
this section is to check that the inputs conform to our dimensionality constraints
|
||||
this section is to check that the inputs conform to our dimensionality
|
||||
constraints
|
||||
"""
|
||||
if X.ndim != 1:
|
||||
print("Error: Input data set must be one dimensional")
|
||||
@ -72,7 +79,8 @@ class Decision_Tree:
|
||||
"""
|
||||
loop over all possible splits for the decision tree. find the best split.
|
||||
if no split exists that is less than 2 * error for the entire array
|
||||
then the data set is not split and the average for the entire array is used as the predictor
|
||||
then the data set is not split and the average for the entire array is used as
|
||||
the predictor
|
||||
"""
|
||||
for i in range(len(X)):
|
||||
if len(X[:i]) < self.min_leaf_size:
|
||||
@ -136,7 +144,7 @@ class Test_Decision_Tree:
|
||||
helper_mean_squared_error_test:
|
||||
@param labels: a one dimensional numpy array
|
||||
@param prediction: a floating point value
|
||||
return value: helper_mean_squared_error_test calculates the mean squared error
|
||||
return value: helper_mean_squared_error_test calculates the mean squared error
|
||||
"""
|
||||
squared_error_sum = np.float(0)
|
||||
for label in labels:
|
||||
@ -147,9 +155,10 @@ class Test_Decision_Tree:
|
||||
|
||||
def main():
|
||||
"""
|
||||
In this demonstration we're generating a sample data set from the sin function in numpy.
|
||||
We then train a decision tree on the data set and use the decision tree to predict the
|
||||
label of 10 different test values. Then the mean squared error over this test is displayed.
|
||||
In this demonstration we're generating a sample data set from the sin function in
|
||||
numpy. We then train a decision tree on the data set and use the decision tree to
|
||||
predict the label of 10 different test values. Then the mean squared error over
|
||||
this test is displayed.
|
||||
"""
|
||||
X = np.arange(-1.0, 1.0, 0.005)
|
||||
y = np.sin(X)
|
||||
|
Reference in New Issue
Block a user