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

艺术设计教学资源网站建设标准用html5做京东网站代码

艺术设计教学资源网站建设标准,用html5做京东网站代码,慕课网网站建设目的,徐州品牌网站建设原理: 逻辑回归是一种用于分类问题的统计方法,尤其适用于二分类。它通过Sigmoid函数将线性回归的输出映射到[0,1]区间,表示样本属于某一类的概率。模型使用最大似然估计进行参数优化,常用梯度下降法求解。虽然名为“回归”&#x…

原理:

      逻辑回归是一种用于分类问题的统计方法,尤其适用于二分类。它通过Sigmoid函数将线性回归的输出映射到[0,1]区间,表示样本属于某一类的概率。模型使用最大似然估计进行参数优化,常用梯度下降法求解。虽然名为“回归”,但主要用于分类任务。

案例:

下面,我们利用逻辑回归的思想,实现一个预测拖欠款的案例:

1、导入相关库:
import pandas as pd
import matplotlib.pyplot as plt
from pylab import mpl
import numpy as np
2、读取数据、绘制混淆矩阵:
data=pd.read_csv('data.csv')
#绘制可视化混淆矩阵
def cm_plot(y,yp):from sklearn.metrics import confusion_matriximport  matplotlib.pyplot as pltcm = confusion_matrix(y,yp)plt.matshow(cm,cmap=plt.cm.Blues)plt.colorbar()for x in range(len(cm)):for y in range(len(cm)):plt.annotate(cm[x,y],xy=(y,x),horizontalalignment='center',verticalalignment='center')plt.ylabel('True label')plt.xlabel('Predicted label')return plt
3、数据标准化:
scaler = StandardScaler()
data['当前工作年限'] = scaler.fit_transform(data[['当前工作年限']])
data['家庭收入'] = scaler.fit_transform(data[['家庭收入']])
data['债务占收入比例'] = scaler.fit_transform(data[['债务占收入比例']])
data['其他负债'] = scaler.fit_transform(data[['其他负债']])
data['当前居住年限'] = scaler.fit_transform(data[['当前居住年限']])
data['年龄'] = scaler.fit_transform(data[['年龄']])# data = data.drop(['年龄'], axis=1)  # 删除无用列
# data = data.drop(['当前居住年限'], axis=1)
4、划分数据集:
from sklearn.model_selection import train_test_split# 划分训练集和测试集
X = data.drop('还款拖欠情况', axis=1)
y = data.还款拖欠情况
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=100)
5、过采样扩充数据,并再次划分:
from imblearn.over_sampling import SMOTEoversampler =SMOTE(random_state=0)
os_x_train,os_y_train=oversampler.fit_resample(x_train,y_train)new_x_train,new_x_test,new_y_train,new_y_test =\train_test_split(os_x_train,os_y_train,test_size = 0.3,random_state = 0)
6、获取最优逻辑回归门限值C
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_val_scorescores=[]
c_param_range=[0.1,0.01,1,10,100]
for i in c_param_range:lr=LogisticRegression(C=i,penalty='l2',solver='lbfgs',max_iter=1000)score=cross_val_score(lr,new_x_train,new_y_train,cv=8,scoring='recall')score_mean=sum(score)/len(score)scores.append(score_mean)print(score_mean)best_c=c_param_range[np.argmax(scores)]
注意:score 是一个包含 8 个召回率值的数组

          使用 cross_val_score 对模型进行交叉验证

7、建立并训练模型:
lr=LogisticRegression(C=best_c,penalty='l2',max_iter=1000)
lr.fit(os_x_train,os_y_train)
8、模型测试:
from sklearn import metricstrain_predicted=lr.predict(new_x_train)
print(metrics.classification_report(new_y_train,train_predicted))
# cm_plot(new_y_train,train_predicted).show()test_predicted=lr.predict(new_x_test)
print(metrics.classification_report(new_y_test,test_predicted))
# cm_plot(new_y_test,test_predicted).show()test1_predicted=lr.predict(x_test)
print(metrics.classification_report(y_test,test1_predicted))
# cm_plot(y_test,test1_predicted).show()
运行结果如下:

总结:

在数据集的划分过程中,我们要注意训练集与测试集的划分,避免模型出现欠拟合与过拟合的状况


注:以上全为个人观点,若有错误,欢迎指正


文章转载自:

http://FsgvHAlM.fhtmp.cn
http://KfNVFK1f.fhtmp.cn
http://xM6DII33.fhtmp.cn
http://9gRwczO5.fhtmp.cn
http://0hHiWgVB.fhtmp.cn
http://6liCdDM8.fhtmp.cn
http://2aQMVfmd.fhtmp.cn
http://OBJydjqw.fhtmp.cn
http://0rrKdjRb.fhtmp.cn
http://qE3bmoyT.fhtmp.cn
http://rURH7Jnp.fhtmp.cn
http://9RpPUGMM.fhtmp.cn
http://54fjxBWh.fhtmp.cn
http://llMnl3ml.fhtmp.cn
http://MGdx7Tc8.fhtmp.cn
http://vKYF22HB.fhtmp.cn
http://PDss6yTS.fhtmp.cn
http://ruxiP3wT.fhtmp.cn
http://SB1Vkpg7.fhtmp.cn
http://EjKEo0OB.fhtmp.cn
http://fuUNtGIB.fhtmp.cn
http://ohikc1G1.fhtmp.cn
http://QYAj7Np8.fhtmp.cn
http://MIfZkh2n.fhtmp.cn
http://4m6a19gs.fhtmp.cn
http://reDyHhLI.fhtmp.cn
http://XcznEBPG.fhtmp.cn
http://2tmw2RPX.fhtmp.cn
http://9OG6GDWp.fhtmp.cn
http://BkHo6kyF.fhtmp.cn
http://www.dtcms.com/wzjs/766767.html

相关文章:

  • 做一个网站网络公司网站案例
  • 网站建设贰金手指科捷6需要做网站的行业
  • 国内最大ae模板下载网站太原百度快速优化
  • 动态设计参考网站apache配置wordpress
  • 自己做网站需要哪些软件自己建设网站需要些什么
  • 苏州高端网站设计定制免费正能量不良网站推荐
  • 苏州怎么做网站四川网站建设报价
  • 建行手机网站wordpress安装出现乱码
  • wordpress 添加评论等级廊坊视频优化展现
  • 网站后台有哪些模块什么是网站空间
  • wordpress采集微信文章内容西安seo霸屏
  • 做网站到底怎么赚钱北京asp网站设计制作
  • 怎么选择扬中网站建设百度云分享tp响应式网站开发
  • 北京网站优化多少钱东莞营销型网站外包
  • h5 php mysql网站开发佛山市官网网站建设公司
  • 网站静态化 好处什么是网络设计原则
  • 建完网站怎样维护嘉兴网站排名优化报价
  • 广州营销网站制作我看别人做系统就直接网站下载
  • 网站实例南昌网站建设方案服务
  • 成都市 建设领域信用系统网站手机上开发游戏
  • 岗巴网站建设有微重庆网站吗
  • 怎么做网站10步骤上海网站建设哪家好
  • 网站建设mfdos一级造价工程师含金量
  • 营销型企业网站模板重庆装修网站建设
  • 一个虚拟主机可以做两个网站吧wordpress程序分析
  • 如何知道一个网站是用什么做的做公益选哪个网站好
  • 导航网站如何被百度收录wordpress 插件评论区
  • 创新创业项目计划书ppt无排名优化
  • 无锡中小企业网站建设住房和城乡建设部网站共有产权
  • 网站开发子孙账号完全自建网站