当前位置: 首页 > news >正文

php免费源码网站互联网推广渠道

php免费源码网站,互联网推广渠道,深圳福田网站建设公司哪家好,做网站的公司广州利用皮马印第安人糖尿病数据集来预测皮马印第安人的糖尿病,以下是数据集的信息: Pregnancies:怀孕次数Glucose:葡萄糖BloodPressure:血压 (mm Hg)SkinThickness:皮层厚度 (mm)Insulin:胰岛素 2…

利用皮马印第安人糖尿病数据集来预测皮马印第安人的糖尿病,以下是数据集的信息:

  • Pregnancies:怀孕次数
  • Glucose:葡萄糖
  • BloodPressure:血压 (mm Hg)
  • SkinThickness:皮层厚度 (mm)
  • Insulin:胰岛素 2小时血清胰岛素(mu U / ml )
  • BMI:体重指数 (体重/身高)^2
  • DiabetesPedigreeFunction:糖尿病谱系功能
  • Age:年龄 (岁)
  • Outcome:目标值 (0或1)

导入模块

# 导入模块包
import pandas as pd
from sklearn.model_selection import train_test_split
import xgboost as xgb
import warnings
warnings.filterwarnings('ignore')
from sklearn.metrics import roc_auc_score, roc_curve, confusion_matrix, classification_report
import matplotlib.pyplot as plt
import seaborn as sns

读取数据

df = pd.read_csv('pima-indians-diabetes.csv')
print(df.info())
df.head()

在这里插入图片描述
由于数据比较完整,不存在数据缺失的问题,所以数据不用处理。

直接进行预测

# 数据划分
feature_columns = ['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness', 'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age']
X = df[feature_columns]
y = df['Outcome']
train_X, test_X, train_y, test_y = train_test_split(X,y,random_state=7,test_size=0.2)
# 模型设置和训练
xgb_clf = xgb.XGBClassifier(n_estimators=20, max_depth=4,learning_rate=0.1,subsample=0.7,colsample_bytree=0.7)
xgb_clf.fit(train_X, train_y)
pred_y = xgb_clf.predict(test_X)
prob_y = xgb_clf.predict_proba(test_X)[:,1]
prob_train_y = xgb_clf.predict_proba(train_X)[:,1]# 模型评估
auc_score = roc_auc_score(test_y, pred_y)
auc_score_train = roc_auc_score(train_y, prob_train_y)
fpr, tpr,_ = roc_curve(test_y, prob_y)
fpr_tr, tpr_tr,_ = roc_curve(train_y, prob_train_y)# 绘制roc曲线
plt.plot(fpr,tpr,label = 'test xgb auc=%0.3f'%auc_score) #绘制训练集ROC 
plt.plot(fpr_tr,tpr_tr,label = 'train xgb auc=%0.3f'%auc_score_train) #绘制验证集ROC 
plt.plot([0,1],[0,1],'k--') 
plt.xlabel('False positive rate') 
plt.ylabel('True positive rate') 
plt.title('ROC Curve') 
plt.legend(loc = 'best') 
plt.show()
print(confusion_matrix(pred_y,test_y))
print((pred_y!=test_y).sum()/float(test_y.shape[0]))
print(classification_report(test_y,pred_y,  target_names=['Yes','No']))

在这里插入图片描述

用xgboost对特征进行筛选,由于上面已经直接用于分类了,所以我们可直接提取出特征的指标。

# 使用xgboost进行特征筛选
temp=pd.DataFrame()
temp['feature_name'] = feature_columns
temp['feature_importance'] = xgb_clf.feature_importances_
temp.sort_values('feature_importance', ascending=False)

在这里插入图片描述
使用筛选过后的特征进行模型训练,使用前四的特征进行训练。

# 使用大于0.1的特征进行训练
feature_lst = ['Glucose','BMI','Age','Insulin']
X = df[feature_lst]
y = df['Outcome']
train_X, test_X, train_y, test_y = train_test_split(X,y,random_state=7,test_size=0.2)
# 模型设置和训练
xgb_clf = xgb.XGBClassifier(n_estimators=20, max_depth=4,learning_rate=0.1,subsample=0.7,colsample_bytree=0.7)
xgb_clf.fit(train_X, train_y)
pred_y = xgb_clf.predict(test_X)
prob_y = xgb_clf.predict_proba(test_X)[:,1]
prob_train_y = xgb_clf.predict_proba(train_X)[:,1]# 模型评估
auc_score = roc_auc_score(test_y, pred_y)
auc_score_train = roc_auc_score(train_y, prob_train_y)
fpr, tpr,_ = roc_curve(test_y, prob_y)
fpr_tr, tpr_tr,_ = roc_curve(train_y, prob_train_y)# 绘制roc曲线
plt.plot(fpr,tpr,label = 'test xgb auc=%0.3f'%auc_score) #绘制训练集ROC 
plt.plot(fpr_tr,tpr_tr,label = 'train xgb auc=%0.3f'%auc_score_train) #绘制验证集ROC 
plt.plot([0,1],[0,1],'k--') 
plt.xlabel('False positive rate') 
plt.ylabel('True positive rate') 
plt.title('ROC Curve') 
plt.legend(loc = 'best') 
plt.show()
print(confusion_matrix(pred_y,test_y))
print((pred_y!=test_y).sum()/float(test_y.shape[0]))
print(classification_report(test_y,pred_y,  target_names=['Yes','No']))

在这里插入图片描述

总结

  • 经过特征筛选后的模型没有得到加强
  • 训练集和测试集的auc值变动较大,泛化能力较弱,需要对数据进行K折验证。
http://www.tj-hxxt.cn/news/115586.html

相关文章:

  • 学院网站建设流程长春seo技术
  • 建设银行网站一直打不开江门seo外包公司
  • wordpress 手机不显示图片优化师是一份怎样的工作
  • 网站测试页面怎么做百度排名怎么做
  • 汽车建设网站的能力win10优化大师好用吗
  • 宜宾网站建设费用seo优化顾问服务
  • 司局网站维护廉政风险建设自己有域名怎么建网站
  • 交互设计网站推荐网站站点
  • 外贸在哪些网站开发客户seo基础教程使用
  • 什么是移动端网站适配学生班级优化大师
  • 做电影网站要几G空间的360摄像头海澳門地区限制解除
  • jquery 素材的网站网络广告投放
  • 都有什么类别的网站台州网站建设优化
  • 2015做哪些网站能致富百度正版下载
  • 微信网页版公众号网站怎么做网站提交收录软件
  • wordpress全文检索杭州seo技术
  • 星斗科技 网站建设长沙百度关键词搜索
  • 佛山建设外贸网站公司吗seo外链推广
  • 济宁住房和城乡建设局网站2345软件为什么没人管
  • 网站策划步骤百度推广有用吗
  • 网站开发进度设计与阶段目标惠州百度seo找谁
  • 利用云服务器做网站建网站教程
  • 淘宝客云建站网址百度如何添加店铺位置信息
  • 桂林网站建设官网百度关键词优化点击 教程
  • 托管代运营海淀区seo全面优化
  • 做木皮的网站vi设计
  • 临沂网站建设费用百度关键词首页排名怎么上
  • 建网站要钱吗google推广公司
  • 广州网站推广网络营销软文范例500字
  • 自己做的网站标题色盲测试图第五版