程序员的自我救赎,使用python开发性格分析工具

python-霍兰德人格分析 #HollandRadarDraw import numpy as np import matplotlib.pyplot as plt import matplotlib matplotlib.rcParams['font.family']='SimHei' radar_labels = np.array(['研究型(I)','艺术型(A)','社会型(S)',\ ... 阅读详情
5847426-2cb3b9f593e25ecc.png
自我救赎
帕累托法则

上世纪初,意大利经济学家维尔弗雷多▪帕累托发现了一个有趣的现象:
在意大利, 大约80%的财富掌握在大约20%的人手中,这在后来被概括为帕累托法则(80/20法则),即二八法则。
而全球财富报告称,中国最富有的那10%的人,拥有中国64%的财富。

如此不均衡的贫富差距,各行业的领导者如何能管理好公司,让员工们即努力产出,又能安于现状呢?每个领导者必学的一门课程就是职场心理学。只有你充分了解员工心理与对应的行为表现,才能从容的掌控各类型的人员,从而达到“物尽其用”。

5847426-1e995b3daa56ec75.png
职场管理

那么职场心理学到底学习什么?

九型人格

九型人格是一个近年来倍受国际著名大学MBA学员推崇的课程之一,近十几年来已风行欧美学术界及工商界。
全球500强企业的管理阶层均有研习九型性格,并以此培训员工,建立团队,提高执行力。在当代,它对于企业的前期规划、战略确定、教练指导、企业培训等方面,九型人格有很大的优势。
九型人格不仅仅是一种精妙的性格分析工具,更主要的是为个人修养、自我提升和历练提供更深入的洞察力。

5847426-34e50d70ccb15647.png
九型人格

俗话说:“龙生九子,子子不同”。通过九型人格的性格分析工具,将性格心理与行为划分为九类。再对不同性格的人群进行研究分析,找到每一类人最适合岗位与职责。这就是领导者们运筹与帷幄之中,决胜于千里之外的筹码。

人为刀俎,我为鱼肉。不想受制于领导者们的掌控,首先要了解自身的人格分类,才能完善自己的不足。这该如何下手?作为程序员,让我们用代码完成自我的救赎吧!

代码改变世界

刚刚过去的华为HR事件,给我印象最深的不是各阶层的矛盾,而是那位HR说的一句话:

在每位开发的心中,都曾有着一个代码改变世界的愿望!

5847426-672b11b2c36c78aa.png
奋斗

那么今天,我们就用Python开发一套九型人格性格分析工具。用以让更多的人,了解自己的性格分类!

既然是九型人格分析,首先我们需要拿到它的测试题。翻了很久,知道了百度文库的测试原题:
https://wenku.baidu.com/view/19455024dd36a32d72758105.html

5847426-2974d88a3d390381.png
测试题

测试题总共36道,通过各场景下的行为表现,最终分析出你最接近的人格分类。现在题有了,如何做出测试题呢?我选择使用Python的tkinter模块,将测试题开发为一个可执行的exe工具,说干就干!

基础准备

为了能将代码打包成单独的可执行文件,我们需要先准备测试题与对应的答案,然后提前存储在代码中。我们需要进行相关拆分,这种苦力活就交给拥有雷锋精神的我来完成吧:


5847426-3848bec4ac70aa09.gif
拆分题目
界面开发

界面无需太过复杂,提供说明、题目、选项作答、题目切换与操作按钮即可。当然,交卷后,需要显示用户的测试结果,那么开始吧!

30 minutes later...完成!

# -*- coding: utf-8 -*-
# @Author   : 王翔
# @微信号   : King_Uranus
# @公众号    : 清风Python
# @GitHub   : https://github.com/BreezePython
# @Date     : 2019/11/12 23:12
# @Software : PyCharm
# @version  :Python 3.7.3
# @File     : Enneagram_GUI.py


# coding:utf-8
from tkinter import *
import Enneagram_Exam
import Enneagram_Result
import tkinter.messagebox

# 自测说明
Standard = '此份问卷共有36道测试题目,请在每题中选择你认为最恰当或者最接近描述自己的性格行为的句子,\n' \
           '请全部作答,最高分的项目很可能成为你的基本性格型态。'

# 人格类型矩阵
Style_Dict = [
    {3: 2, 6: 2, 10: 2, 15: 2, 19: 1, 22: 2, 28: 2, 32: 2},
    {1: 1, 6: 1, 12: 1, 17: 2, 20: 1, 23: 1, 29: 1, 33: 1},
    {4: 1, 7: 1, 10: 1, 14: 2, 23: 2, 26: 2, 30: 1, 34: 1},
    {2: 1, 8: 2, 12: 2, 16: 1, 21: 2, 24: 1, 28: 1, 34: 2},
    {1: 2, 4: 2, 13: 1, 16: 2, 19: 2, 25: 1, 31: 1, 36: 1},
    {5: 1, 9: 2, 14: 1, 18: 1, 21: 1, 25: 2, 29: 2, 32: 1},
    {2: 2, 7: 2, 11: 2, 18: 2, 22: 1, 27: 2, 33: 2, 36: 2},
    {3: 1, 9: 1, 13: 2, 17: 1, 24: 2, 27: 1, 20: 2, 35: 2}
]


class ExamPage:
    def __init__(self, master=None):
        self.root = master
        # 用户结果集
        self.user_result = {}
        self.status = 1
        self.All_Exam = Enneagram_Exam
        self.normal_choice = IntVar()
        self.start_exam()

    # 上一题方法
    def before(self):
        if self.normal_choice.get() != 0:
            self.user_result[self.status] = self.normal_choice.get()
            if self.status > 1:
                self.status -= 1
                self.body.grid_forget()
                self.main_exam()
        else:
            tkinter.messagebox.showwarning("提示:", message="请先选择答案!")

    # 下一题方法
    def after(self):
        if self.normal_choice.get() != 0:
            self.user_result[self.status] = self.normal_choice.get()
            if self.status < len(Enneagram_Exam.Exam):
                self.status += 1
                self.body.grid_forget()
                self.main_exam()
        else:
            tkinter.messagebox.showwarning("提示:", message="请先选择答案!")

    # 获取当前题目
    def exam_files(self, num):
        return list(map(lambda x: x.split('.'), self.All_Exam.Exam[num - 1].strip().split('\n')))

    # 交卷
    def hand_paper(self):
        self.user_result[self.status] = self.normal_choice.get()
        if len(self.user_result) != 36:
            tkinter.messagebox.showwarning("提示:", message="您还有未完成的测试题!")
        else:
            self.exam_result = LabelFrame(self.root, text="测试结果", padx=10, pady=10, fg="red", font=("黑体", '11'))
            self.exam_result.grid(padx=10, pady=5, sticky=NSEW)
            sc = Scrollbar(self.exam_result)
            sc.grid(row=0, column=1, sticky=NS)
            result_info = Text(self.exam_result, font=("黑体", '11'), width=85, yscrollcommand=sc.set)
            result_info.grid(row=0, column=0, sticky=NSEW)
            sc.config(command=result_info.yview)
            all_num = []
            for style in Style_Dict:
                calc_num = list(
                    point for point in self.user_result if point in style and self.user_result[point] == style[point])
                if calc_num == None:
                    all_num.append(0)
                else:
                    all_num.append(len(calc_num))
            user_type = all_num.index(max(all_num))
            for line in Enneagram_Result.Result[user_type]:
                result_info.insert(END, line)

    # 启动测试所需控制按钮
    def start_exam(self):
        self.title = LabelFrame(self.root, text="自测说明", padx=10, pady=10, fg="red", font=("黑体", '11'))
        self.title.grid(padx=10, pady=5)
        note = Label(self.title, text=Standard, justify=LEFT, font=("黑体", '11'))
        note.grid()
        self.show = LabelFrame(self.root, text="选项", padx=10, pady=10, fg="red", font=("黑体", '11'))
        self.show.grid(padx=10, pady=5, sticky=EW)
        go_back = Button(self.show, text="上一题", width=8, command=lambda: self.before())
        go_back.grid(row=4, column=0, padx=5, pady=10)
        to_forword = Button(self.show, text="下一题", width=8, command=lambda: self.after())
        to_forword.grid(row=4, column=1, padx=5, pady=10, sticky=E)
        hand_in = Button(self.show, text="交卷", width=8, command=lambda: self.hand_paper())
        hand_in.grid(row=4, column=2, padx=5, pady=10, sticky=E)
        exit_sys = Button(self.show, text="退出", width=8, command=lambda: sys.exit())
        exit_sys.grid(row=4, column=3, padx=5, pady=10, sticky=E)
        self.main_exam()

    # 测试题主界面
    def main_exam(self):
        self.normal_choice.set(0)
        self.body = LabelFrame(self.root,
                               text="测试题  第%s题,剩余%s题" % (self.status, (len(Enneagram_Exam.Exam) - self.status)),
                               padx=10, pady=10, fg="red", font=("黑体", '11'))
        self.body.grid(padx=10, pady=5, sticky=EW)
        for option, choice in self.exam_files(self.status):
            authority_choice = Radiobutton(self.body, text=choice, variable=self.normal_choice, value=option)
            authority_choice.grid(row=option, sticky=W)
        Label(self.body, text="  第%s道题,用户选择的结果是:" % self.status, fg="red", font=("黑体", '11')).grid(row=3, column=0,
                                                                                                   sticky=W)
        Label(self.body, textvariable=self.normal_choice).grid(row=3, column=0, sticky=E)

对于一位程序员的审美,大家不要要求的过高,重点来关注下功能实现吧!当然在此之前我们需要先将代码打包为exe。

5847426-a7050614804245a6.gif
打包测试

功能OK了,现在不要打扰我,我要做题了!


5847426-3daf36b94facb6a3.png
测试结果

我的答案是完美型,处女座总是在追求完美的路上跟自己死磕,哎...活得好累。
今天的内容就到这里了,程序的代码及打包好的exe已经放到百度云了,公众号回复测试获下载链接。记得测试后,告诉我你的所属的类型哦!

The End
5847426-0630448b3d3cd916.png
清风Python
往期精选

有了它,从此走上炫酷的编码之路!
使用python假装黑客,批量破解朋友的网站密码
不给糖果就捣乱,用Python绘制有趣的万圣节南瓜怪
Python帮你微信头像任意添加装饰,别再@微信官方了!
使用Python开发小说下载器,不再为下载小说而发愁

Python简单预测模型 在数据科学和机器学习中,预测模型是一种重要的工具,用于根据历史数据推断未来的趋势和结果。Python是一种功能强大的编程语言,提供了许多库和工具,使我们能够轻松地构建和部署预测模型。本文将介绍如何使用Python构建一个简单的预测模型,并提供相应的源代码。在本文中,我们介绍了如何使用NumPy和Scikit-learn库构建一个简单的预测模型,并给出了相应的源代码。在这个例子中,我们将使用一个简单的数据集,其中包含了房屋的面积和价格。在实际应用中,我们通常会使用更复杂的模型和更多的特征来进行预测。 阅读详情

相关推荐

九型人格测试题.144题.excel版可直接得出结果.xls

九型人格测试题 144题 excel版 可直接得出结果

python实现人格分析

很抱歉,我无法理解您的问题。您是想问如何使用 Python 进行人格分析吗?请注意,人格分析是一个复杂的问题,需要专业的心理学知识和技能才能正确进行。若您想尝试用 Python 实现人格分析,可以考虑使用已有的人格测试数据(例如李克特量表)和机器学习模型,但是这需要您具备一定的机器学习知识和技能。我建议您先学习相关的知识再尝试进行人格分析。 ...

weixin_42588672的博客 430

易语言源码易语言性格色彩测试软件源码.rar

易语言源码易语言性格色彩测试软件源码.rar 易语言源码易语言性格色彩测试软件源码.rar 易语言源码易语言性格色彩测试软件源码.rar 易语言源码易语言性格色彩测试软件源码.rar 易语言源码易语言性格色彩测试软件源码.rar 易语言源码易语言性格色彩测试软件源码.rar易语言源码易语言性格色彩测试软件源码.rar 易语言源码易语言性格色彩测试软件源码.rar

基于python的数据分析系统,python数据分析经典案例

大家好,本文将围绕利用python进行数据分析案例展开说明,基于python的数据分析系统是一个很多人都想弄明白的事情,想搞清楚基于python的数据分析题目需要先了解以下几个事情。

chatgpt002的博客 1673

针对Python的代码静态分析工具PySonar.zip

PySonar2 是王垠开发的,针对 Python 的代码静态分析工具,现在这项技术被著名的代码搜索引擎  Sourcegraph 使用,这是 PySonar 的第二个版本,第一个版本的使用者是 Google 内部,作为 Python 上百万行高质量语义代码索引。 更多特性说明请看作者博客: http://yinwang0.wordpress.com/2010/09/12/pysonar 构建 mvn package 使用 PySonar2 主要是作为 Python IDEs ,其他开发工具和代码搜索引擎的一个库,所以接口并不像终端应用。构建简单的,基于 Python 2.7 标准库的 "code-browser": java -jar target/pysonar-2.0-SNAPSHOT.jar /usr/lib/python2.7 ./html 系统要求 Python 2.7.x Python 3.x if you have Python3 files Java 7 maven 标签:PySonar

人格测试的python代码实现通过代码测试你的人格魅力

人格测试的python程序,just for fun,有兴趣的可以下下来玩一下

九型人格----概述

一、什么是九型人格? 九型人格又名性格型态学。九种性格,是婴儿时期人身上的九种气质。它能帮助我们了解人类不同的个性与特质,探索人与人相处之道的学问。 解决什么问题: 1、是什么?(是什么性格类型的人) 2、为什么?(为什么这样做) 3、需要什么?(需要什么能更好) 4、如何调整自己能做得到 5、我为什么要这样做 用于改变自己,去影响别人 注意: 每个人只对应一种人格 从心态上分类 每个人关注的事...

李笑男的博客 7937

智能农业大棚

目 录 摘要 1.绪论 2.系统概述及单片机介绍 2.1整体方案设计思想 2.2系统组成 2.2.1主控芯片的选择 2.2.2传感器模块选择 2.2.3电机驱动模块 2.3 单片机介绍 2.3.1 AT89C51单片机的基本组成 2.3.2AT89C51主要特性 2.3.3管脚说明 2.3.4 AT89C51单片机的存储器 2.3.4.1 程序存储器 2.3.4.2 数据存储器 2.3.5 振荡电路和时钟 2.3.6 AT89C51的中断

weixin_70886450的博客 1327

程序员的自我救赎,使用Python开发性格分析工具

帕累托法则上世纪初,意大利经济学家维尔弗雷多▪帕累托发现了一个有趣的现象:在意大利, 大约80%的财富掌握在大约20%的人手中,这在后来被概括为帕累托法则(80/20法则),即二八法则...

cainiao_python的博客 483

储能电站 BMS 与车载动力电池 BMS 核心差异:工况、保护策略、控制逻辑对比

储能电站BMS与车载动力电池BMS虽同名,实为针对不同赛道量身定制的产品。简单地将车载BMS方案套用于储能,或将储能BMS思路用于车载,都可能带来性能、安全或成本上的严重问题。在选择和设计BMS时,必须回归其应用场景的本质需求储能BMS是**“资产管理者”**,精打细算,追求在长达十余年的服役期内稳定、高效地创造收益。车载BMS是**“性能与安全卫士”**,反应敏捷,确保在车辆全生命周期内动力澎湃且万无一失。

小帽子的博客 423

储能系统架构和控制

探讨了储能系统中EMS(能源管理系统)、BMS(电池管理系统)和PCS(功率转换系统)之间的协同机制,以及组串式和集中式储能系统的技术架构、优势和局限性。EMS根据电价、电网需求和电池状态制定充放电策略,BMS提供电池数据,PCS执行充放电控制。组串式系统具有独立管理和灵活扩展的优势,但成本较高;集中式系统成本效益高,但存在环流和木桶效应问题。

蓝龙宝藏的博客 3969

用python开发自己的攻击工具_程序员的自我救赎,使用Python开发性格分析工具

如此不均衡的贫富差距,各行业的领导者如何能管理好公司,让员工们既努力产出,又能安于现状呢?每个领导者必学的一门课程就是职场心理学。只有你充分了解员工心理与对应的行为表现,才能从容的掌控各类型的人员,从而达到“物尽其用”。那么职场心理学到底学习什么?九型人格九型人格是一个近年来倍受国际著名大学MBA学员推崇的课程之一,近十几年来已风行欧美学术界及工商界。全球500强企业的管理阶层均有研习九型性格,并...

weixin_28759537的博客 185

【研究生学术英语读写教程翻译 中国科学院大学Unit9】

Unit 9 If Humble People Make the Best Leaders,Why Do We Fall for Charismatic Narcissists? 如果谦逊的人是最好的领导者,为什么我们会爱上魅力型自恋者?

fuhanghang的博客 4101

程序员的自我救赎,使用python开发性格分析工具(1)

from Enneagram_GUI import *from tkinter import *def center_window(root, width, height):screenwidth = root.winfo_screenwidth()screenheight = root.winfo_screenheight()size = ‘%dx%d+%d+%d’ % (width, height, (screenwidth - width) / 2, (screenheight - height) /

2401_83642079的博客 1072

宇树GO2-YOLOv5在Jetson Orin上的部署避坑实践

本文详细记录了在宇树GO2四足机器人搭载的Jetson Orin平台上部署YOLOv5目标检测模型的完整实践过程。文章重点分享了从ARM架构认知、网络连接解决方案、Archiconda环境搭建、PyTorch版本精准匹配到依赖安装与性能验证的核心步骤与避坑指南,旨在帮助开发者高效完成边缘计算环境下的算法部署。

app77的博客 669

告别JavaScript!C#通过WebAssembly在浏览器中实现“原生级“性能

C# + WebAssembly:前端开发的革命性替代方案 摘要:本文探讨了C#通过WebAssembly取代JavaScript开发前端应用的新趋势。文章分析了JavaScript的局限性(弱类型、回调地狱等),并详细介绍了C#+WebAssembly组合的优势:强类型系统、高性能、多线程支持和代码重用。技术实现方面,阐述了C#通过Mono/.NET编译为WebAssembly字节码的原理,重点介绍了Blazor框架的两种模式。文章还提供了实战指南,包括项目创建、多线程配置,以及一个与ChatGPT AP

墨夶的博客 946

messagebox 全部使用_程序员的自我救赎,使用Python开发性格分析工具

帕累托法则上世纪初,意大利经济学家维尔弗雷多▪帕累托发现了一个有趣的现象:在意大利, 大约80%的财富掌握在大约20%的人手中,这在后来被概括为帕累托法则(80/20法则),即二八法则。而全球财富报告称,中国最富有的那10%的人,拥有中国64%的财富。如此不均衡的贫富差距,各行业的领导者如何能管理好公司,让员工们即努力产出,又能安于现状呢?每个领导者必学的一门课程就是职场心理学。只有你充...

weixin_39752157的博客 212

计算机等级考试(二级WPS)---真题14套

目录 真题14一、选择题二、WPS文字三、WPS表格四、WPS演示21.打开考生文件夹下的素材文档 “WPS.docx”(.docx 为文件扩展名),后续操作均基于此文件,否则不得分。小周正在整理一份关于极光的文档,请按要求帮助她完成文档的排版工作。1.将全文中的手动换行符全部替换为中文句号并回车,删除文中的空行和空格。2.将正文第 2 段(“在我國的古書…… 極光”)中的繁体字转换成简体字,并为其设置 “正文” 样式。3.对文档样式进行如下设置:4.为 “1.3 极光的形态” 一节中列出的五种极光形态特征

2401_82750246的博客 1176

python程序员自我评价_程序员的自我救赎,使用python开发性格分析工具

https://wenku.baidu.com/view/19455024dd36a32d72758105.html测试题总共36道,通过各场景下的行为表现,最终分析出你最接近的人格分类。现在题有了,如何做出测试题呢?我选择使用Python的tkinter模块,将测试题开发为一个可执行的exe工具,说干就干!基础准备为了能将代码打包成单独的可执行文件,我们需要先准备测试题与对应的答案,然后提前存储...

weixin_39918961的博客 690

【ACP】2025-最新-疑难题解析- 练习二汇总

全球加速是优化公网访问的,负载均衡是分发流量的,公网 NAT 网关是处理公网 IP 的,高速通道是建私网连接但不直接提供固定私网地址功能。C 是客户端加密方式,D 是 ECS 云盘加密,都不属于 OSS 服务器端加密。某企业想使用云服务器 ECS + 负载均衡 SLB + 弹性伸缩 (Auto Scaling) 的架构搭建一个企业级门户网站,技术负责人对于负载均衡和弹性伸缩配合使用没有经验,于是将他理解的两种产品配合使用的一些技术细节列成了一个表单,并请作为架构师的您帮他做一下鉴别,以下哪些项是正确的?

jundao1997的专栏 295

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 我不愿与"你"只如初见
下一篇: 将安卓手机打造成你的python全栈开发利器
清风Python
博客等级 码龄7年 406粉丝 267原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值