没有合适的资源?快使用搜索试试~ 我知道了~
神经网络实验报告 陈诺1
需积分: 0 0 下载量 199 浏览量
2022-08-08
23:04:52
上传
评论
收藏 912KB DOCX 举报
温馨提示
试读
15页
实际上,可以用稍微不同的法对数据进划分:将样本按3:1的比例分割为6093个训练集和2031个测试集:from sklearn.model_selection
资源详情
资源评论
资源推荐
华东师范大学数据学院实践报告
课程名称: 专业英语
年级:大二
指导教师:周烜
姓名:陈诺
上机实践名称: 手搭神经网络
学号: 10175501112
上机实践日期:2019.6
一、 目的
利用 python 手搭神经网络
二、 内容与设计思想
本次作业名称:Neural Network Practice
作业内容:本次作业主要是希望通过实践,加深大家对于神经网络的理解。
作业的数据集:
https://www.kaggle.com/uciml/mushroom-classification#mushrooms.csv
Classification data Sources,作业内容主要是对收集的 Mushroom 数据进行
分类,判断是否有毒,具体的数据格式
以及详细要求参考以上链接。
作业要求:使用自己搭建的人工神经网络模型完成 Classification 任务,并
且对模型进行不断优化,将准确率提升到极
限。希望同学们自己动手搭建神经网络。代码实现可以参考教科书中的手
写数字识别样例代码 neural-networksand-
deep-learning。不推荐使用已有的集成 Machine Learning 库,⽐如:keras,
sklearn 等。目的是让大家深入
体会神经网络的构造细节。
提交材料:
1. 报告一份,描述神经网络的构建过程、优化过程、参数选择的考虑、
以及心得体会。
2. 代码一份。
提交时间:7 月 4 日
参考资料:http://neuralnetworksanddeeplearning.com/index.html
三、 使用环境
Python3.7
四、 实验过程
首先要进行数据处理,这里将毒蘑菇置 0 不毒置 1,并将参数映射到 0-1 范围 内,
使参数相对联系较为紧密。
由于其中有一列缺失‘?’值较多,故不失一般性,将此参数删去,数据大小变
为 8124*22。
data=data.drop('stalk-root',axis=1)#缺省太多的特征不去考虑
顺便提一下,它共有 8124 个样本。实际上,可以用稍微不同的�法对数据进�
划分:
将样本按 3:1 的比例分割为 6093 个训练集和 2031 个测试集:
from sklearn.model_selection import train_test_split
X, y = datanp[:, 1:], datanp[:, 0]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=0)
以下是加在数据的细节:
import pickle
import gzip
# def load_data():
# f = gzip.open('../data/mnist.pkl.gz', 'rb')
# training_data, validation_data, testing_data = pickle.load(f,encoding='bytes')
def load_data_wrapper(train_data,test_data):
"""Return a tuple containing ``(training_data, validation_data,
test_data)``. Based on ``load_data``, but the format is more
convenient for use in our implementation of neural networks.
In particular, ``training_data`` is a list containing 50,000
2-tuples ``(x, y)``. ``x`` is a 784-dimensional numpy.ndarray
containing the input image. ``y`` is a 10-dimensional
numpy.ndarray representing the unit vector corresponding to the
correct digit for ``x``.
``validation_data`` and ``test_data`` are lists containing 10,000
2-tuples ``(x, y)``. In each case, ``x`` is a 784-dimensional
numpy.ndarry containing the input image, and ``y`` is the
corresponding classification, i.e., the digit values (integers)
corresponding to ``x``.
Obviously, this means we're using slightly different formats for
the training data and the validation / test data. These formats
turn out to be the most convenient for use in our neural network
code."""
tr_d, te_d = train_data,test_data
training_inputs = [np.reshape(x, (21, 1)) for x in tr_d[0]]
training_results = [vectorized_result(y) for y in tr_d[1]]
training_data = zip(training_inputs, training_results)
test_inputs = [np.reshape(x, (21, 1)) for x in te_d[0]]
test_results = [vectorized_result(y) for y in te_d[1]]
test_data = zip(test_inputs, test_results)
training_data=list(training_data)
test_data=list(test_data)
return (training_data,test_data)
def vectorized_result(j):
"""Return a 10-dimensional unit vector with a 1.0 in the jth
position and zeroes elsewhere. This is used to convert a digit
(0,1) into a corresponding desired output from the neural
network."""
e = np.zeros((2, 1))
e[j] = 1.0
return e
其将 train_data,test_data 变换成为我们需要的格式。
剩余14页未读,继续阅读
航知道
- 粉丝: 27
- 资源: 302
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0