diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs000.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs000.html index 532859bcb..cd7951257 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs000.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs000.html @@ -125,7 +125,8 @@ Automatically generated HTML file from DocOnce source ('Gradient Boosting, algorithm', 2, None, '___sec50'), ('Gradient Boosting, Examples', 2, None, '___sec51'), ('Gradient Boots with Early Stopping', 2, None, '___sec52'), - ('XGBoost: Extreme Gradient Boosting', 2, None, '___sec53')]} + ('XGBoost: Extreme Gradient Boosting', 2, None, '___sec53'), + ('Xgboost on the Cancer Data', 2, None, '___sec54')]} end of tocinfo -->
@@ -217,6 +218,7 @@ MathJax.Hub.Config({+ + +
import matplotlib.pyplot as plt
+import numpy as np
+from sklearn.model_selection import train_test_split
+from sklearn.datasets import load_breast_cancer
+from sklearn.preprocessing import LabelEncoder
+from sklearn.model_selection import cross_validate
+import scikitplot as skplt
+import xgboost as xgb
+# Load the data
+cancer = load_breast_cancer()
+
+X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
+print(X_train.shape)
+print(X_test.shape)
+#now scale the data
+from sklearn.preprocessing import StandardScaler
+scaler = StandardScaler()
+scaler.fit(X_train)
+X_train_scaled = scaler.transform(X_train)
+X_test_scaled = scaler.transform(X_test)
+
+xg_clf = xgb.XGBClassifier()
+xg_clf.fit(X_train_scaled,y_train)
+xgb.plot_tree(xg_clf,num_trees=0)
+plt.rcParams['figure.figsize'] = [50, 10]
+plt.show()
+xgb.plot_importance(xg_clf)
+plt.rcParams['figure.figsize'] = [5, 5]
+plt.show()
+It is now the algorithm which wins essentially all ML competitions!!! +
+
+
+
+ + +
import matplotlib.pyplot as plt
+import numpy as np
+from sklearn.model_selection import train_test_split
+from sklearn.datasets import load_breast_cancer
+from sklearn.preprocessing import LabelEncoder
+from sklearn.model_selection import cross_validate
+import scikitplot as skplt
+import xgboost as xgb
+# Load the data
+cancer = load_breast_cancer()
+
+X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
+print(X_train.shape)
+print(X_test.shape)
+#now scale the data
+from sklearn.preprocessing import StandardScaler
+scaler = StandardScaler()
+scaler.fit(X_train)
+X_train_scaled = scaler.transform(X_train)
+X_test_scaled = scaler.transform(X_test)
+
+xg_clf = xgb.XGBClassifier()
+xg_clf.fit(X_train_scaled,y_train)
+xgb.plot_tree(xg_clf,num_trees=0)
+plt.rcParams['figure.figsize'] = [50, 10]
+plt.show()
+xgb.plot_importance(xg_clf)
+plt.rcParams['figure.figsize'] = [5, 5]
+plt.show()
++ diff --git a/doc/pub/DecisionTrees/html/DecisionTrees.html b/doc/pub/DecisionTrees/html/DecisionTrees.html index 2b45b7595..186eea8a1 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees.html @@ -150,7 +150,8 @@ div { text-align: justify; text-justify: inter-word; } ('Gradient Boosting, algorithm', 2, None, '___sec50'), ('Gradient Boosting, Examples', 2, None, '___sec51'), ('Gradient Boots with Early Stopping', 2, None, '___sec52'), - ('XGBoost: Extreme Gradient Boosting', 2, None, '___sec53')]} + ('XGBoost: Extreme Gradient Boosting', 2, None, '___sec53'), + ('Xgboost on the Cancer Data', 2, None, '___sec54')]} end of tocinfo -->
@@ -2227,6 +2228,45 @@ sketch for efficient proposal calculation. It introduces a novel sparsity-awareIt is now the algorithm which wins essentially all ML competitions!!! +
+
+
+
+ + +
import matplotlib.pyplot as plt
+import numpy as np
+from sklearn.model_selection import train_test_split
+from sklearn.datasets import load_breast_cancer
+from sklearn.preprocessing import LabelEncoder
+from sklearn.model_selection import cross_validate
+import scikitplot as skplt
+import xgboost as xgb
+# Load the data
+cancer = load_breast_cancer()
+
+X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
+print(X_train.shape)
+print(X_test.shape)
+#now scale the data
+from sklearn.preprocessing import StandardScaler
+scaler = StandardScaler()
+scaler.fit(X_train)
+X_train_scaled = scaler.transform(X_train)
+X_test_scaled = scaler.transform(X_test)
+
+xg_clf = xgb.XGBClassifier()
+xg_clf.fit(X_train_scaled,y_train)
+xgb.plot_tree(xg_clf,num_trees=0)
+plt.rcParams['figure.figsize'] = [50, 10]
+plt.show()
+xgb.plot_importance(xg_clf)
+plt.rcParams['figure.figsize'] = [5, 5]
+plt.show()
++ diff --git a/doc/pub/DecisionTrees/ipynb/DecisionTrees.ipynb b/doc/pub/DecisionTrees/ipynb/DecisionTrees.ipynb index 666e15bc7..b0eaa13f3 100644 --- a/doc/pub/DecisionTrees/ipynb/DecisionTrees.ipynb +++ b/doc/pub/DecisionTrees/ipynb/DecisionTrees.ipynb @@ -2288,7 +2288,48 @@ "boosting system. It has a theoretically justified weighted quantile\n", "sketch for efficient proposal calculation. It introduces a novel sparsity-aware algorithm for parallel tree learning and an effective cache-aware block structure for out-of-core tree learning.\n", "\n", - "It is now the algorithm which wins essentially all ML competitions!!!" + "It is now the algorithm which wins essentially all ML competitions!!!\n", + "\n", + "## Xgboost on the Cancer Data" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "from sklearn.model_selection import train_test_split \n", + "from sklearn.datasets import load_breast_cancer\n", + "from sklearn.preprocessing import LabelEncoder\n", + "from sklearn.model_selection import cross_validate\n", + "import scikitplot as skplt\n", + "import xgboost as xgb\n", + "# Load the data\n", + "cancer = load_breast_cancer()\n", + "\n", + "X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)\n", + "print(X_train.shape)\n", + "print(X_test.shape)\n", + "#now scale the data\n", + "from sklearn.preprocessing import StandardScaler\n", + "scaler = StandardScaler()\n", + "scaler.fit(X_train)\n", + "X_train_scaled = scaler.transform(X_train)\n", + "X_test_scaled = scaler.transform(X_test)\n", + "\n", + "xg_clf = xgb.XGBClassifier()\n", + "xg_clf.fit(X_train_scaled,y_train)\n", + "xgb.plot_tree(xg_clf,num_trees=0)\n", + "plt.rcParams['figure.figsize'] = [50, 10]\n", + "plt.show()\n", + "xgb.plot_importance(xg_clf)\n", + "plt.rcParams['figure.figsize'] = [5, 5]\n", + "plt.show()" ] } ], diff --git a/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz b/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz index 1d7d28def..8efd3d870 100644 Binary files a/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz and b/doc/pub/DecisionTrees/ipynb/ipynb-DecisionTrees-src.tar.gz differ diff --git a/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf b/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf index 85c249036..4556a78e2 100644 Binary files a/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf and b/doc/pub/DecisionTrees/pdf/DecisionTrees-minted.pdf differ diff --git a/doc/src/DecisionTrees/DecisionTrees.do.txt b/doc/src/DecisionTrees/DecisionTrees.do.txt index 5f8f1fc91..3d35629da 100644 --- a/doc/src/DecisionTrees/DecisionTrees.do.txt +++ b/doc/src/DecisionTrees/DecisionTrees.do.txt @@ -1847,3 +1847,37 @@ boosting system. It has a theoretically justified weighted quantile sketch for efficient proposal calculation. It introduces a novel sparsity-aware algorithm for parallel tree learning and an effective cache-aware block structure for out-of-core tree learning. It is now the algorithm which wins essentially all ML competitions!!! + +!split +===== Xgboost on the Cancer Data ===== +!bc pycod +import matplotlib.pyplot as plt +import numpy as np +from sklearn.model_selection import train_test_split +from sklearn.datasets import load_breast_cancer +from sklearn.preprocessing import LabelEncoder +from sklearn.model_selection import cross_validate +import scikitplot as skplt +import xgboost as xgb +# Load the data +cancer = load_breast_cancer() + +X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0) +print(X_train.shape) +print(X_test.shape) +#now scale the data +from sklearn.preprocessing import StandardScaler +scaler = StandardScaler() +scaler.fit(X_train) +X_train_scaled = scaler.transform(X_train) +X_test_scaled = scaler.transform(X_test) + +xg_clf = xgb.XGBClassifier() +xg_clf.fit(X_train_scaled,y_train) +xgb.plot_tree(xg_clf,num_trees=0) +plt.rcParams['figure.figsize'] = [50, 10] +plt.show() +xgb.plot_importance(xg_clf) +plt.rcParams['figure.figsize'] = [5, 5] +plt.show() +!ec diff --git a/doc/src/DecisionTrees/Programs/xgcancer.py b/doc/src/DecisionTrees/Programs/xgcancer.py new file mode 100644 index 000000000..55d910b0d --- /dev/null +++ b/doc/src/DecisionTrees/Programs/xgcancer.py @@ -0,0 +1,33 @@ +import matplotlib.pyplot as plt +import numpy as np +from sklearn.model_selection import train_test_split +from sklearn.datasets import load_breast_cancer +from sklearn.preprocessing import LabelEncoder +from sklearn.model_selection import cross_validate +import scikitplot as skplt +import xgboost as xgb +# Load the data +cancer = load_breast_cancer() + +X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0) +print(X_train.shape) +print(X_test.shape) +#now scale the data +from sklearn.preprocessing import StandardScaler +scaler = StandardScaler() +scaler.fit(X_train) +X_train_scaled = scaler.transform(X_train) +X_test_scaled = scaler.transform(X_test) + +xg_clf = xgb.XGBClassifier() +xg_clf.fit(X_train_scaled,y_train) + +preds = xg_clf.predict(X_test_scaled) + +xgb.plot_tree(xg_clf,num_trees=0) +plt.rcParams['figure.figsize'] = [50, 10] +plt.show() + +xgb.plot_importance(xg_clf) +plt.rcParams['figure.figsize'] = [5, 5] +plt.show()