#分类案例,样本不均衡
import numpy as np
import pandas as pd
from xgboost import XGBClassifier
from sklearn.datasets import make_blobs
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix,recall_score,roc_auc_score
import matplotlib.pyplot as plt
#制造不平衡数据集
class1=500000
class2=50000
centers=[[0.0,0.0],[10.0,10.0]]
clusters_std=[7.5,3]
X,y=make_blobs(n_samples=[class1,class2]
,centers=centers
,cluster_std=clusters_std
,random_state=0,shuffle=False)#shuffle:将数据进行洗乱,默认值是True
X.shape
#接下来使用sklearn库进行建模
Xtrain,Xtest,ytrain,ytest=train_test_split(X,y,test_size=0.3,random_state=0)
clf=XGBClassifier().fit(Xtrain,ytrain)
preds=clf.predict(Xtest)