34 lines
954 B
Python
34 lines
954 B
Python
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()
|