scikit类学习接口和chainer的堆栈式自动编码器

zChainer的Python项目详细描述


Scikit Learn Like界面和Chainer的堆叠自动编码器

要求

  • 努比
  • SCIKIT学习
  • chainer=1.5

安装

pip install zChainer

用法

自动编码器

importnumpyasnpimportchainer.functionsasFimportchainer.linksasLfromchainerimportChainList,optimizersfromzChainerimportNNAutoEncoder,utilitydata=(..).astype(np.float32)encoder=ChainList(L.Linear(784,200),L.Linear(200,100))decoder=ChainList(L.Linear(200,784),L.Linear(100,200))# You can set your own forward function. Default is as below.#def forward(self, x):#    h = F.dropout(F.relu(self.model[0](x)))#    return F.dropout(F.relu(self.model[1](h)))##NNAutoEncoder.forward = forwardae=NNAutoEncoder(encoder,decoder,optimizers.Adam(),epoch=100,batch_size=100,log_path="./ae_log_"+utility.now()+".csv",export_path="./ae_"+utility.now()+".model")ae.fit(data)

培训和测试

importnumpyasnpimportchainer.functionsasFimportchainer.linksasLfromchainerimportChainList,optimizersfromzChainerimportNNManager,utilityimportpickleX_train=(..).astype(np.float32)y_train=(..).astype(np.int32)X_test=(..).astype(np.float32)y_test=(..).astype(np.int32)# Create a new networkmodel=ChainList(L.Linear(784,200),L.Linear(200,100),L.Linear(100,10))# or load a serialized model#f = open("./ae_2015-12-01_11-26-45.model")#model = pickle.load(f)#f.close()#model.add_link(L.Linear(100,10))defforward(self,x):h=F.relu(self.model[0](x))h=F.relu(self.model[1](h))returnF.relu(self.model[2](h))defoutput(self,y):y_trimed=y.data.argmax(axis=1)returnnp.array(y_trimed,dtype=np.int32)NNManager.forward=forwardNNManager.output=outputnn=NNManager(model,optimizers.Adam(),F.softmax_cross_entropy,epoch=100,batch_size=100,log_path="./training_log_"+utility.now()+".csv")nn.fit(X_train,y_train,is_classification=True)nn.predict(X_test,y_test)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在通过url读取csv文件时,我想用数据映射列名   java在没有类型转换的情况下访问父类型的arraylist中的特定子类型方法,子类型的创建只有在运行时才知道   java扩展UIComponentBase时如何保存状态   java如何使用字符串作为Velocity模板?   用于调试远程/本地java应用程序的自定义调试器   JavaFx和浮动按钮   java如何修改列表中的对象?在迭代时扩展MyObject>?   java Spring框架如何避免控制器中的重复代码?   java代码名1 IOS签名   一点Bitly API有Java库吗?   jasper报告将Highcharts图表添加到使用JavaAPI生成的JasperReport模板中   swing如何在java中更改按键的颜色   java Javax Websocket使用路径参数提交登录数据,好的做法?