update
This commit is contained in:
@@ -686,7 +686,6 @@ plt.plot(polydegree, error, label='Error')
|
||||
plt.plot(polydegree, bias, label='bias')
|
||||
plt.plot(polydegree, variance, label='Variance')
|
||||
plt.legend()
|
||||
save_fig("gdregression")
|
||||
plt.show()
|
||||
!ec
|
||||
|
||||
@@ -725,14 +724,11 @@ print("Test set accuracy with Gradient boosting and scaled data: {:.2f}".format(
|
||||
import scikitplot as skplt
|
||||
y_pred = gd_clf.predict(X_test_scaled)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
|
||||
save_fig("gdclassiffierconfusion")
|
||||
plt.show()
|
||||
y_probas = gd_clf.predict_proba(X_test_scaled)
|
||||
skplt.metrics.plot_roc(y_test, y_probas)
|
||||
save_fig("gdclassiffierroc")
|
||||
plt.show()
|
||||
skplt.metrics.plot_cumulative_gain(y_test, y_probas)
|
||||
save_fig("gdclassiffiercgain")
|
||||
plt.show()
|
||||
!ec
|
||||
|
||||
@@ -754,53 +750,6 @@ sketch for efficient proposal calculation. It introduces a novel sparsity-aware
|
||||
|
||||
It is now the algorithm which wins essentially all ML competitions!!!
|
||||
|
||||
!split
|
||||
===== Regression Case =====
|
||||
|
||||
!bc pycod
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from sklearn.model_selection import train_test_split
|
||||
import xgboost as xgb
|
||||
import scikitplot as skplt
|
||||
from sklearn.metrics import mean_squared_error
|
||||
|
||||
n = 100
|
||||
maxdegree = 6
|
||||
|
||||
# Make data set.
|
||||
x = np.linspace(-3, 3, n).reshape(-1, 1)
|
||||
y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape)
|
||||
|
||||
error = np.zeros(maxdegree)
|
||||
bias = np.zeros(maxdegree)
|
||||
variance = np.zeros(maxdegree)
|
||||
polydegree = np.zeros(maxdegree)
|
||||
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
|
||||
|
||||
for degree in range(maxdegree):
|
||||
model = xgb.XGBRegressor(objective ='reg:squarederror', colsaobjective ='reg:squarederror', colsample_bytree = 0.3, learning_rate = 0.1,max_depth = degree, alpha = 10, n_estimators = 200)
|
||||
|
||||
model.fit(X_train,y_train)
|
||||
y_pred = model.predict(X_test)
|
||||
polydegree[degree] = degree
|
||||
error[degree] = np.mean( np.mean((y_test - y_pred)**2) )
|
||||
bias[degree] = np.mean( (y_test - np.mean(y_pred))**2 )
|
||||
variance[degree] = np.mean( np.var(y_pred) )
|
||||
print('Max depth:', degree)
|
||||
print('Error:', error[degree])
|
||||
print('Bias^2:', bias[degree])
|
||||
print('Var:', variance[degree])
|
||||
print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
|
||||
plt.xlim(1,maxdegree-1)
|
||||
plt.plot(polydegree, error, label='Error')
|
||||
plt.plot(polydegree, bias, label='bias')
|
||||
plt.plot(polydegree, variance, label='Variance')
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
!ec
|
||||
|
||||
!split
|
||||
===== Xgboost on the Cancer Data =====
|
||||
@@ -839,25 +788,20 @@ print("Test set accuracy with Gradient Boosting and scaled data: {:.2f}".format(
|
||||
import scikitplot as skplt
|
||||
y_pred = xg_clf.predict(X_test_scaled)
|
||||
skplt.metrics.plot_confusion_matrix(y_test, y_pred, normalize=True)
|
||||
save_fig("xdclassiffierconfusion")
|
||||
plt.show()
|
||||
y_probas = xg_clf.predict_proba(X_test_scaled)
|
||||
skplt.metrics.plot_roc(y_test, y_probas)
|
||||
save_fig("xdclassiffierroc")
|
||||
plt.show()
|
||||
skplt.metrics.plot_cumulative_gain(y_test, y_probas)
|
||||
save_fig("gdclassiffiercgain")
|
||||
plt.show()
|
||||
|
||||
|
||||
xgb.plot_tree(xg_clf,num_trees=0)
|
||||
plt.rcParams['figure.figsize'] = [50, 10]
|
||||
save_fig("xgtree")
|
||||
plt.show()
|
||||
|
||||
xgb.plot_importance(xg_clf)
|
||||
plt.rcParams['figure.figsize'] = [5, 5]
|
||||
save_fig("xgparams")
|
||||
plt.show()
|
||||
|
||||
!ec
|
||||
|
||||
Reference in New Issue
Block a user