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

软件开发技术培训课程成都自然排名优化

软件开发技术培训课程,成都自然排名优化,深圳市最新疫情情况,房产中介如何做网站pytorch实战 课时7 神经网络 MSE的缺点:偏导值在输出概率值接近0或者接近1的时候非常小,这可能会造成模型刚开始训练时,偏导值几乎消失,模型速度非常慢。 交叉熵损失函数:平方损失则过于严格,需要使用更合…

pytorch实战

课时7 神经网络
  1. MSE的缺点:偏导值在输出概率值接近0或者接近1的时候非常小,这可能会造成模型刚开始训练时,偏导值几乎消失,模型速度非常慢。

  2. 交叉熵损失函数:平方损失则过于严格,需要使用更合适衡量两个概率分布差异的测量函数。
    使用逻辑函数得到概率,并结合交叉熵当损失函数时,在模型效果差的时候学习速度比较快,在模型效果好的时候学习速度变慢。

  3. torch.randint(0,2,(10,))
    报错:torch.randint(0,2,(10))必须要有逗号

  4. x.view()相当于reshape。x.view((-1, 4))当第一个参数为-1时,自动调整为n行4列的张量

  5. 写模型时需要注意:

    • super(LinearNet,self).init()
    • forward(self, X):
  6. 查看模型参数:net.state_dict()

机器学习算法(一): 基于逻辑回归的分类预测

天池学习地址

逻辑回归使用交叉熵作为损失函数,我理解的步骤为:

  1. 初始化w和b,计算所有点的y值。
  2. 利用sigmoid函数将y值转化为属于某一类的概率
  3. 利用交叉熵损失,希望损失最小,不断更新w和b

下面是天池的具体内容:

# 可视化决策边界
plt.figure()
plt.scatter(x_fearures[:,0],x_fearures[:,1], c=y_label, s=50, cmap='viridis') # 绘制三点图
plt.title('Dataset')# x割裂成200份,y为100,生成网格矩阵,存储网格矩阵的点,20000个点。画图的时候,不需要一定按照x和y的坐标,使用网格坐标也可
nx, ny = 200, 100
x_min, x_max = plt.xlim()
y_min, y_max = plt.ylim() # 边界的大小
x_grid, y_grid = np.meshgrid(np.linspace(x_min, x_max, nx),np.linspace(y_min, y_max, ny)) #x_grid, y_grid的大小都是100*200,计数是从左下到右上# 根据网格矩阵,也就是有20000个点,计算每个点分别为1类和2类的概率,z_proba的结果
''' array([[0.98401648, 0.01598352],[0.98362875, 0.01637125],[0.98323179, 0.01676821],...,[0.01094403, 0.98905597],[0.01068344, 0.98931656],[0.01042899, 0.98957101]]) '''
z_proba = lr_clf.predict_proba(np.c_[x_grid.ravel(), y_grid.ravel()]) # ravel()将二维合成一维
z_proba = z_proba[:, 1].reshape(x_grid.shape) # 此时z_proba是对应的类别1的预测概率
plt.contour(x_grid, y_grid, z_proba, [0.5], linewidths=2., colors='blue') # 绘制等高线的函数,例如画一座山。XY的坐标,和山的高度plt.show()

下面是分析iris数据集的一般步骤:

  1. 数据集的读取,转化为pandas元素

    iris_target = data.target #得到数据对应的标签
    iris_features = pd.DataFrame(data=data.data, columns=data.feature_names) #利用Pandas转化为DataFrame格式
    
  2. 查看数据集的基本信息:

    # 这些函数是pandas的,所以数据格式为Series和DataFrame
    ## 利用.info()查看数据的整体信息
    iris_features.info()
    ## 进行简单的数据查看,我们可以利用 .head() 头部.tail()尾部
    iris_features.head()
    iris_features.tail()
    ## 其对应的类别标签为,其中0,1,2分别代表'setosa', 'versicolor', 'virginica'三种不同花的类别。
    iris_target
    ## 利用value_counts函数查看每个类别数量
    pd.Series(iris_target).value_counts()
    ## 对于特征进行一些统计描述
    iris_features.describe()
    
  3. 可视化描述:散点和箱线图

    ## 特征与标签组合的散点可视化
    sns.pairplot(data=iris_all,diag_kind='hist', hue= 'target')
    plt.show()
    ## 箱线图
    for col in iris_features.columns:sns.boxplot(x='target', y=col, saturation=0.5,palette='pastel', data=iris_all)plt.title(col)plt.show()
  4. 利用模型进行训练:划分数据集,定义模型,模型训练,打印参数

    ## 划分数据集
    from sklearn.model_selection import train_test_split
    x_train, x_test, y_train, y_test = train_test_split(iris_features_part, iris_target_part, test_size = 0.2, random_state = 2020)
    ## 模型训练
    from sklearn.linear_model import LogisticRegression
    clf = LogisticRegression(random_state=0, solver='lbfgs')
    clf.fit(x_train, y_train)
    clf.coef_
    clf.intercept_
    
  5. 利用模型进行测试,可视化测试结果:预测结果和概率,计算混淆矩阵,利用矩阵和热力图可视化

    ## 测试结果是一个array,类别和概率分别如下
    test_predict = clf.predict(x_test)
    test_predict_proba = clf.predict_proba(x_test)
    ## 正确率计算
    from sklearn import metrics
    print('The accuracy of the Logistic Regression is:',metrics.accuracy_score(y_test,test_predict))
    ## 查看混淆矩阵
    confusion_matrix_result = metrics.confusion_matrix(test_predict,y_test)
    # 利用热力图对于结果进行可视化
    plt.figure(figsize=(8, 6))
    sns.heatmap(confusion_matrix_result, annot=True, cmap='Blues')
    plt.xlabel('Predicted labels')
    plt.ylabel('True labels')
    plt.show()
    

文章转载自:
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://www.tj-hxxt.cn/news/36878.html

相关文章:

  • 公司网站维护怎么做互联网营销软件
  • 响应式自助建站平台谷歌seo网站建设
  • 淄博做网站电话微信附近人推广引流
  • 建站源码下载徐州网页关键词优化
  • 程序员除了做软件是不是就做网站衡阳网站优化公司
  • wordpress主题转换seo职业技能培训班
  • 外贸网站建设szjijie下载百度app
  • 域名的申请流程seo优化排名
  • wifi办理一个月多少钱网站优化排名易下拉系统
  • 如何创建自己的网站营销推广seo
  • WordPress京东自动转链插件北京seo优化wyhseo
  • 广告链接网页怎么做的seo入门培训课程
  • 网站推广要具备什么最火的网络推广平台
  • 网站建设公司赚钱吗排名优化系统
  • 咸阳网站建设电话深圳互联网公司排行榜
  • 微信24小时人工申诉seo搜索引擎优化到底是什么
  • 免费h5生成网站免费行情网站的推荐理由
  • 做网站架构自媒体平台排名
  • 怎么做58同城网站优化网络的软件下载
  • 专业建设网站的企业推广营销
  • 做网站用什么服务器夜夜草
  • 做网站排名赚钱吗海南百度推广开户
  • 淄博北京网站建设微信营销怎么做
  • 手表交易网站互联网下的网络营销
  • 建网站免费搜狗seo
  • 网站描述 修改seo业务培训
  • 手机网站模板免费下载百度反馈中心
  • phpnow安装wordpress冯耀宗seo课程
  • 潍坊网站建设平台西安外包公司排行
  • 没有自己的网站做百度竞价seo关键词排名注册价格