From 1bd73042b5899f7f187ed7bbe8e4cccfdf7b0be5 Mon Sep 17 00:00:00 2001 From: Modassir Afzal Date: Thu, 13 Oct 2022 17:19:51 +0530 Subject: [PATCH 01/20] Fixes: #{6551} --- machine_learning/xgboostclassifier.py | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 machine_learning/xgboostclassifier.py diff --git a/machine_learning/xgboostclassifier.py b/machine_learning/xgboostclassifier.py new file mode 100644 index 000000000000..0707eb130002 --- /dev/null +++ b/machine_learning/xgboostclassifier.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +"""xgboostclassifier.ipynb + +Automatically generated by Colaboratory. + +Original file is located at + https://colab.research.google.com/drive/1UlMmSrfKLuRW9LPCz6BvDDJMPgPhO-yu +""" + +# XGBoost Classifier Example +from matplotlib import pyplot as plt +from sklearn.datasets import load_iris +from xgboost import XGBClassifier +from sklearn.metrics import plot_confusion_matrix +from sklearn.model_selection import train_test_split + + +def main(): + + """ + The Url for the algorithm + https://xgboost.readthedocs.io/en/stable/ + Iris type dataset is used to demonstrate algorithm. + """ + + # Load Iris dataset + iris = load_iris() + + # Split dataset into train and test data + x = iris["data"] # features + y = iris["target"] + x_train, x_test, y_train, y_test = train_test_split( + x, y, test_size=0.3, random_state=1 + ) + + # XGBoost Classifier + xgb = XGBClassifier() + xgb.fit(x_train, y_train) + + # Display Confusion Matrix of Classifier + plot_confusion_matrix( + xgb, + x_test, + y_test, + display_labels=iris["target_names"], + cmap="Blues", + normalize="true", + ) + plt.title("Normalized Confusion Matrix - IRIS Dataset") + plt.show() + + +if __name__ == "__main__": + main() \ No newline at end of file From 7477e9fcaade0a0134c12c13efaa5ca259de8b9a Mon Sep 17 00:00:00 2001 From: Modassir Afzal Date: Thu, 13 Oct 2022 17:21:14 +0530 Subject: [PATCH 02/20] Fixes: #{6551} --- machine_learning/xgboostregressor.py | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 machine_learning/xgboostregressor.py diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py new file mode 100644 index 000000000000..9aa14116c22b --- /dev/null +++ b/machine_learning/xgboostregressor.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +"""xgboostregressor.ipynb + +Automatically generated by Colaboratory. + +Original file is located at + https://colab.research.google.com/drive/1UrXXhxQNEI3rL3182GyZFCqPqyhE1c5g +""" + +# XGBoost Regressor Example +from sklearn.datasets import load_boston +from xgboost import XGBRegressor +from sklearn.metrics import mean_absolute_error, mean_squared_error +from sklearn.model_selection import train_test_split + + +def main(): + + """ + The Url for the algorithm + https://xgboost.readthedocs.io/en/stable/ + Boston house price dataset is used to demonstrate the algorithm. + """ + # Load Boston house price dataset + boston = load_boston() + print(boston.keys()) + + # Split dataset into train and test data + x = boston["data"] # features + y = boston["target"] + x_train, x_test, y_train, y_test = train_test_split( + x, y, test_size=0.25, random_state=1 + ) + + #XGBoost Regressor + xgb=XGBRegressor() + xgb.fit(x_train, y_train) + + # Predict target for test data + predictions = xgb.predict(x_test) + predictions = predictions.reshape(len(predictions), 1) + + # Error printing + print(f"Mean Absolute Error:\t {mean_absolute_error(y_test, predictions)}") + print(f"Mean Square Error :\t {mean_squared_error(y_test, predictions)}") + + +if __name__ == "__main__": + main() \ No newline at end of file From c2759c4e503b48b35fd7580615dd97ce81a18f56 Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Thu, 13 Oct 2022 17:33:28 +0530 Subject: [PATCH 03/20] Update xgboostclassifier.py --- machine_learning/xgboostclassifier.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/machine_learning/xgboostclassifier.py b/machine_learning/xgboostclassifier.py index 0707eb130002..082a082c8e15 100644 --- a/machine_learning/xgboostclassifier.py +++ b/machine_learning/xgboostclassifier.py @@ -1,12 +1,3 @@ -# -*- coding: utf-8 -*- -"""xgboostclassifier.ipynb - -Automatically generated by Colaboratory. - -Original file is located at - https://colab.research.google.com/drive/1UlMmSrfKLuRW9LPCz6BvDDJMPgPhO-yu -""" - # XGBoost Classifier Example from matplotlib import pyplot as plt from sklearn.datasets import load_iris @@ -15,7 +6,7 @@ from sklearn.model_selection import train_test_split -def main(): +def main() -> None: """ The Url for the algorithm @@ -51,4 +42,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() From d6d84d4524394add80fc00b20ef771899a61f1dd Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Thu, 13 Oct 2022 17:34:36 +0530 Subject: [PATCH 04/20] Delete xgboostclassifier.py --- machine_learning/xgboostclassifier.py | 45 --------------------------- 1 file changed, 45 deletions(-) delete mode 100644 machine_learning/xgboostclassifier.py diff --git a/machine_learning/xgboostclassifier.py b/machine_learning/xgboostclassifier.py deleted file mode 100644 index 082a082c8e15..000000000000 --- a/machine_learning/xgboostclassifier.py +++ /dev/null @@ -1,45 +0,0 @@ -# XGBoost Classifier Example -from matplotlib import pyplot as plt -from sklearn.datasets import load_iris -from xgboost import XGBClassifier -from sklearn.metrics import plot_confusion_matrix -from sklearn.model_selection import train_test_split - - -def main() -> None: - - """ - The Url for the algorithm - https://xgboost.readthedocs.io/en/stable/ - Iris type dataset is used to demonstrate algorithm. - """ - - # Load Iris dataset - iris = load_iris() - - # Split dataset into train and test data - x = iris["data"] # features - y = iris["target"] - x_train, x_test, y_train, y_test = train_test_split( - x, y, test_size=0.3, random_state=1 - ) - - # XGBoost Classifier - xgb = XGBClassifier() - xgb.fit(x_train, y_train) - - # Display Confusion Matrix of Classifier - plot_confusion_matrix( - xgb, - x_test, - y_test, - display_labels=iris["target_names"], - cmap="Blues", - normalize="true", - ) - plt.title("Normalized Confusion Matrix - IRIS Dataset") - plt.show() - - -if __name__ == "__main__": - main() From 77fcd97eda334c21fe2bdddc216df272f4bd9ecb Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Thu, 13 Oct 2022 17:35:00 +0530 Subject: [PATCH 05/20] Update xgboostregressor.py --- machine_learning/xgboostregressor.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index 9aa14116c22b..3976dbe7533c 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -1,12 +1,3 @@ -# -*- coding: utf-8 -*- -"""xgboostregressor.ipynb - -Automatically generated by Colaboratory. - -Original file is located at - https://colab.research.google.com/drive/1UrXXhxQNEI3rL3182GyZFCqPqyhE1c5g -""" - # XGBoost Regressor Example from sklearn.datasets import load_boston from xgboost import XGBRegressor @@ -14,7 +5,7 @@ from sklearn.model_selection import train_test_split -def main(): +def main() -> None: """ The Url for the algorithm @@ -46,4 +37,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() From 884ccfcf476246199b9284efb3fd586d5acf81c2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 13 Oct 2022 12:06:22 +0000 Subject: [PATCH 06/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- machine_learning/xgboostregressor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index 3976dbe7533c..0e83761708eb 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -1,8 +1,8 @@ # XGBoost Regressor Example from sklearn.datasets import load_boston -from xgboost import XGBRegressor from sklearn.metrics import mean_absolute_error, mean_squared_error from sklearn.model_selection import train_test_split +from xgboost import XGBRegressor def main() -> None: @@ -23,8 +23,8 @@ def main() -> None: x, y, test_size=0.25, random_state=1 ) - #XGBoost Regressor - xgb=XGBRegressor() + # XGBoost Regressor + xgb = XGBRegressor() xgb.fit(x_train, y_train) # Predict target for test data From 7ff3c6a1798d994070b58a17d622cc5af89c0615 Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Thu, 13 Oct 2022 18:01:29 +0530 Subject: [PATCH 07/20] Fixes: #{6551} --- machine_learning/xgboostregressor.py | 1 - 1 file changed, 1 deletion(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index 0e83761708eb..60fac2292f5a 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -22,7 +22,6 @@ def main() -> None: x_train, x_test, y_train, y_test = train_test_split( x, y, test_size=0.25, random_state=1 ) - # XGBoost Regressor xgb = XGBRegressor() xgb.fit(x_train, y_train) From bc626339c8bcb8a545e781d1bc87d337fd2fb86f Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Sat, 15 Oct 2022 01:22:47 +0530 Subject: [PATCH 08/20] Fixes : {#6551} --- machine_learning/xgboostregressor.py | 35 ++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index 60fac2292f5a..10da1bdec7ac 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -5,6 +5,21 @@ from xgboost import XGBRegressor +def dataset(datatype:dict) -> tuple: + # Split dataset into train and test data + x = (datatype["data"],datatype["target"]) # features + return x + + +def xgboost(features:list, target:list,test_features:list) -> list: + xgb = XGBRegressor() + xgb.fit(features, target) + # Predict target for test data + predictions = xgb.predict(test_features) + predictions = predictions.reshape(len(predictions), 1) + return predictions + + def main() -> None: """ @@ -15,20 +30,12 @@ def main() -> None: # Load Boston house price dataset boston = load_boston() print(boston.keys()) - - # Split dataset into train and test data - x = boston["data"] # features - y = boston["target"] + + features, target = dataset(boston) x_train, x_test, y_train, y_test = train_test_split( - x, y, test_size=0.25, random_state=1 + features, target, test_size=0.25, random_state=1 ) - # XGBoost Regressor - xgb = XGBRegressor() - xgb.fit(x_train, y_train) - - # Predict target for test data - predictions = xgb.predict(x_test) - predictions = predictions.reshape(len(predictions), 1) + predictions = xgboost(x_train, y_train, x_test) # Error printing print(f"Mean Absolute Error:\t {mean_absolute_error(y_test, predictions)}") @@ -36,4 +43,8 @@ def main() -> None: if __name__ == "__main__": + import doctest + doctest.testmod(name="main", verbose=True) + doctest.testmod(name="dataset", verbose=True) + doctest.testmod(name="xgboost", verbose=True) main() From 349733d316e42bc3d07b705cfc6344811843a57b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Oct 2022 19:53:44 +0000 Subject: [PATCH 09/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- machine_learning/xgboostregressor.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index 10da1bdec7ac..6af5ec92d875 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -5,13 +5,13 @@ from xgboost import XGBRegressor -def dataset(datatype:dict) -> tuple: +def dataset(datatype: dict) -> tuple: # Split dataset into train and test data - x = (datatype["data"],datatype["target"]) # features + x = (datatype["data"], datatype["target"]) # features return x -def xgboost(features:list, target:list,test_features:list) -> list: +def xgboost(features: list, target: list, test_features: list) -> list: xgb = XGBRegressor() xgb.fit(features, target) # Predict target for test data @@ -30,7 +30,7 @@ def main() -> None: # Load Boston house price dataset boston = load_boston() print(boston.keys()) - + features, target = dataset(boston) x_train, x_test, y_train, y_test = train_test_split( features, target, test_size=0.25, random_state=1 @@ -44,6 +44,7 @@ def main() -> None: if __name__ == "__main__": import doctest + doctest.testmod(name="main", verbose=True) doctest.testmod(name="dataset", verbose=True) doctest.testmod(name="xgboost", verbose=True) From 36f5d87d2bcfa24c54a8cfa7526edcf20aacb530 Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Thu, 20 Oct 2022 00:21:13 +0530 Subject: [PATCH 10/20] Fixes: {#6551] --- machine_learning/xgboostregressor.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index 6af5ec92d875..10db19c533c5 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -7,7 +7,9 @@ def dataset(datatype: dict) -> tuple: # Split dataset into train and test data - x = (datatype["data"], datatype["target"]) # features + features=datatype["data"] + target=datatype["target"] + x = (train_test_split(features, target, test_size=0.25)) return x @@ -17,6 +19,7 @@ def xgboost(features: list, target: list, test_features: list) -> list: # Predict target for test data predictions = xgb.predict(test_features) predictions = predictions.reshape(len(predictions), 1) + print(type(predictions)) return predictions @@ -29,12 +32,8 @@ def main() -> None: """ # Load Boston house price dataset boston = load_boston() - print(boston.keys()) - features, target = dataset(boston) - x_train, x_test, y_train, y_test = train_test_split( - features, target, test_size=0.25, random_state=1 - ) + x_train, x_test, y_train, y_test = dataset(boston) predictions = xgboost(x_train, y_train, x_test) # Error printing From dab31ab352b661abaa3925861164fbaf5ceeea68 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Oct 2022 18:54:01 +0000 Subject: [PATCH 11/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- machine_learning/xgboostregressor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index 10db19c533c5..3ac943c5f4aa 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -7,9 +7,9 @@ def dataset(datatype: dict) -> tuple: # Split dataset into train and test data - features=datatype["data"] - target=datatype["target"] - x = (train_test_split(features, target, test_size=0.25)) + features = datatype["data"] + target = datatype["target"] + x = train_test_split(features, target, test_size=0.25) return x @@ -33,7 +33,7 @@ def main() -> None: # Load Boston house price dataset boston = load_boston() - x_train, x_test, y_train, y_test = dataset(boston) + x_train, x_test, y_train, y_test = dataset(boston) predictions = xgboost(x_train, y_train, x_test) # Error printing From e962c513dc5afd5945bee258f104d359abaf99b8 Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Sat, 22 Oct 2022 03:59:50 +0530 Subject: [PATCH 12/20] Update xgboostregressor.py --- machine_learning/xgboostregressor.py | 57 ++++++++++++++++++---------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index 3ac943c5f4aa..99598a26a5f0 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -1,50 +1,65 @@ # XGBoost Regressor Example -from sklearn.datasets import load_boston +from sklearn.datasets import fetch_california_housing from sklearn.metrics import mean_absolute_error, mean_squared_error from sklearn.model_selection import train_test_split from xgboost import XGBRegressor +import numpy as np +def data_handling(data: dict) -> tuple: + # Split dataset into features and target + # data is features + """ + >>> data_handling(( + ... {'data':'[ 8.3252 41. 6.9841269 1.02380952 322. 2.55555556 37.88 -122.23 ]' + ... ,'target':([4.526])})) + ('[ 8.3252 41. 6.9841269 1.02380952 322. 2.55555556 37.88 -122.23 ]', [4.526]) + """ + return (data["data"], data["target"]) -def dataset(datatype: dict) -> tuple: - # Split dataset into train and test data - features = datatype["data"] - target = datatype["target"] - x = train_test_split(features, target, test_size=0.25) - return x - - -def xgboost(features: list, target: list, test_features: list) -> list: - xgb = XGBRegressor() +def xgboost(features: np.ndarray, target: np.ndarray, test_features: np.ndarray) -> np.ndarray: + """ + >>> xgboost(np.array([[ 2.3571 , 52. , 6.00813008, 1.06775068, + ... 907. , 2.45799458, 40.58 , -124.26]]),np.array([1.114]), + ... np.array([[1.97840000e+00, 3.70000000e+01, 4.98858447e+00, 1.03881279e+00, + ... 1.14300000e+03, 2.60958904e+00, 3.67800000e+01, -1.19780000e+02]])) + array([[1.1103648]], dtype=float32) + """ + xgb = XGBRegressor(verbosity = 0,random_state=42) xgb.fit(features, target) # Predict target for test data predictions = xgb.predict(test_features) predictions = predictions.reshape(len(predictions), 1) - print(type(predictions)) + #print("this is the type ",(features[1],target[1],test_features[1])) return predictions - -def main() -> None: +def main() -> print: """ + >>> main() + Mean Absolute Error : 0.37270180506441014 + Mean Square Error : 0.2933464701930606 + + The Url for the algorithm https://xgboost.readthedocs.io/en/stable/ Boston house price dataset is used to demonstrate the algorithm. """ # Load Boston house price dataset - boston = load_boston() + california = fetch_california_housing() + + data, target = data_handling(california) + x_train, x_test, y_train, y_test = train_test_split( + data, target, test_size=0.25, random_state=1 + ) - x_train, x_test, y_train, y_test = dataset(boston) predictions = xgboost(x_train, y_train, x_test) # Error printing - print(f"Mean Absolute Error:\t {mean_absolute_error(y_test, predictions)}") + print(f"Mean Absolute Error :\t {mean_absolute_error(y_test, predictions)}") print(f"Mean Square Error :\t {mean_squared_error(y_test, predictions)}") if __name__ == "__main__": import doctest - - doctest.testmod(name="main", verbose=True) - doctest.testmod(name="dataset", verbose=True) - doctest.testmod(name="xgboost", verbose=True) + doctest.testmod(verbose=True) main() From 55103efc6af917929288515bc7e6d9ca6facfd78 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 21 Oct 2022 22:31:39 +0000 Subject: [PATCH 13/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- machine_learning/xgboostregressor.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index 99598a26a5f0..fd8c4f52ace9 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -1,9 +1,10 @@ # XGBoost Regressor Example +import numpy as np from sklearn.datasets import fetch_california_housing from sklearn.metrics import mean_absolute_error, mean_squared_error from sklearn.model_selection import train_test_split from xgboost import XGBRegressor -import numpy as np + def data_handling(data: dict) -> tuple: # Split dataset into features and target @@ -16,7 +17,10 @@ def data_handling(data: dict) -> tuple: """ return (data["data"], data["target"]) -def xgboost(features: np.ndarray, target: np.ndarray, test_features: np.ndarray) -> np.ndarray: + +def xgboost( + features: np.ndarray, target: np.ndarray, test_features: np.ndarray +) -> np.ndarray: """ >>> xgboost(np.array([[ 2.3571 , 52. , 6.00813008, 1.06775068, ... 907. , 2.45799458, 40.58 , -124.26]]),np.array([1.114]), @@ -24,21 +28,22 @@ def xgboost(features: np.ndarray, target: np.ndarray, test_features: np.ndarray) ... 1.14300000e+03, 2.60958904e+00, 3.67800000e+01, -1.19780000e+02]])) array([[1.1103648]], dtype=float32) """ - xgb = XGBRegressor(verbosity = 0,random_state=42) + xgb = XGBRegressor(verbosity=0, random_state=42) xgb.fit(features, target) # Predict target for test data predictions = xgb.predict(test_features) predictions = predictions.reshape(len(predictions), 1) - #print("this is the type ",(features[1],target[1],test_features[1])) + # print("this is the type ",(features[1],target[1],test_features[1])) return predictions + def main() -> print: """ >>> main() Mean Absolute Error : 0.37270180506441014 Mean Square Error : 0.2933464701930606 - + The Url for the algorithm https://xgboost.readthedocs.io/en/stable/ @@ -61,5 +66,6 @@ def main() -> print: if __name__ == "__main__": import doctest + doctest.testmod(verbose=True) main() From 9fcc5a81e198fbaaca7d926b6b789dcad81b735e Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Sat, 22 Oct 2022 04:15:22 +0530 Subject: [PATCH 14/20] Update xgboostregressor.py --- machine_learning/xgboostregressor.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index fd8c4f52ace9..ac5d44007826 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -33,7 +33,6 @@ def xgboost( # Predict target for test data predictions = xgb.predict(test_features) predictions = predictions.reshape(len(predictions), 1) - # print("this is the type ",(features[1],target[1],test_features[1])) return predictions @@ -41,8 +40,7 @@ def main() -> print: """ >>> main() - Mean Absolute Error : 0.37270180506441014 - Mean Square Error : 0.2933464701930606 + The Url for the algorithm From c9c439428a22da086eac7d66405bd62b7fc19515 Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Sat, 22 Oct 2022 04:20:15 +0530 Subject: [PATCH 15/20] Update xgboostregressor.py --- machine_learning/xgboostregressor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index ac5d44007826..62f897c64bfc 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -36,7 +36,7 @@ def xgboost( return predictions -def main() -> print: +def main() -> None: """ >>> main() From 3464ba96bb6626c98604d6e6cdddbc90cd23b8e3 Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Sat, 22 Oct 2022 04:38:10 +0530 Subject: [PATCH 16/20] Fixes: { #6551} --- machine_learning/xgboostregressor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index 62f897c64bfc..b887990e4cbb 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -40,7 +40,8 @@ def main() -> None: """ >>> main() - + Mean Absolute Error : 0.30957163379906033 + Mean Square Error : 0.22611560196662744 The Url for the algorithm From 6944c8575a511bb4daa020aa039132acbde88d8a Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Sat, 22 Oct 2022 04:44:29 +0530 Subject: [PATCH 17/20] Update xgboostregressor.py --- machine_learning/xgboostregressor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index b887990e4cbb..10ecfca46740 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -26,7 +26,7 @@ def xgboost( ... 907. , 2.45799458, 40.58 , -124.26]]),np.array([1.114]), ... np.array([[1.97840000e+00, 3.70000000e+01, 4.98858447e+00, 1.03881279e+00, ... 1.14300000e+03, 2.60958904e+00, 3.67800000e+01, -1.19780000e+02]])) - array([[1.1103648]], dtype=float32) + array([[1.1139996]], dtype=float32) """ xgb = XGBRegressor(verbosity=0, random_state=42) xgb.fit(features, target) From a7b6d112c9944f71f0c92d76b9aaa813eb6084c1 Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Sat, 22 Oct 2022 04:56:54 +0530 Subject: [PATCH 18/20] Fixes: { #6551} --- machine_learning/xgboostregressor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index 10ecfca46740..a27ed92da9e2 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -40,8 +40,8 @@ def main() -> None: """ >>> main() - Mean Absolute Error : 0.30957163379906033 - Mean Square Error : 0.22611560196662744 + Mean Absolute Error : 0.30957163379906033 + Mean Square Error : 0.22611560196662744 The Url for the algorithm @@ -59,8 +59,8 @@ def main() -> None: predictions = xgboost(x_train, y_train, x_test) # Error printing - print(f"Mean Absolute Error :\t {mean_absolute_error(y_test, predictions)}") - print(f"Mean Square Error :\t {mean_squared_error(y_test, predictions)}") + print(f"Mean Absolute Error : {mean_absolute_error(y_test, predictions)}") + print(f"Mean Square Error : {mean_squared_error(y_test, predictions)}") if __name__ == "__main__": From 2fbc105cce55dd36f2856efe6e6f09ab55e4a2dd Mon Sep 17 00:00:00 2001 From: Modassir Afzal <60973906+Moddy2024@users.noreply.github.com> Date: Sun, 23 Oct 2022 17:09:47 +0530 Subject: [PATCH 19/20] Fixes: { #6551} --- machine_learning/xgboostregressor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboostregressor.py index a27ed92da9e2..941503a6c8d4 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboostregressor.py @@ -46,9 +46,9 @@ def main() -> None: The Url for the algorithm https://xgboost.readthedocs.io/en/stable/ - Boston house price dataset is used to demonstrate the algorithm. + California house price dataset is used to demonstrate the algorithm. """ - # Load Boston house price dataset + # Load California house price dataset california = fetch_california_housing() data, target = data_handling(california) From e37101edbe619f849aa2fbbf0e8eb9c0b8d9b716 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 23 Oct 2022 13:43:19 +0200 Subject: [PATCH 20/20] Update and rename xgboostregressor.py to xgboost_regressor.py --- .../{xgboostregressor.py => xgboost_regressor.py} | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) rename machine_learning/{xgboostregressor.py => xgboost_regressor.py} (95%) diff --git a/machine_learning/xgboostregressor.py b/machine_learning/xgboost_regressor.py similarity index 95% rename from machine_learning/xgboostregressor.py rename to machine_learning/xgboost_regressor.py index 941503a6c8d4..023984fc1f59 100644 --- a/machine_learning/xgboostregressor.py +++ b/machine_learning/xgboost_regressor.py @@ -7,8 +7,7 @@ def data_handling(data: dict) -> tuple: - # Split dataset into features and target - # data is features + # Split dataset into features and target. Data is features. """ >>> data_handling(( ... {'data':'[ 8.3252 41. 6.9841269 1.02380952 322. 2.55555556 37.88 -122.23 ]' @@ -37,27 +36,22 @@ def xgboost( def main() -> None: - """ >>> main() Mean Absolute Error : 0.30957163379906033 Mean Square Error : 0.22611560196662744 - - The Url for the algorithm + The URL for this algorithm https://xgboost.readthedocs.io/en/stable/ California house price dataset is used to demonstrate the algorithm. """ # Load California house price dataset california = fetch_california_housing() - data, target = data_handling(california) x_train, x_test, y_train, y_test = train_test_split( data, target, test_size=0.25, random_state=1 ) - predictions = xgboost(x_train, y_train, x_test) - # Error printing print(f"Mean Absolute Error : {mean_absolute_error(y_test, predictions)}") print(f"Mean Square Error : {mean_squared_error(y_test, predictions)}")