mlp_clf_mnist_test
import os
os.environ['CUDA_VISIBLE_DEVICES'] = "0"
from mlp_clf import MLPClassifier
import numpy as np
import tensorflow as tf
from sklearn.datasets import load_svmlight_file
from sklearn.utils import shuffle
#from scipy.sparse import csr_matrix
def mean(numbers): #计算平均值
s = 0.0
for num in numbers:
s = s + num
return s/len(numbers)
def dev(numbers, mean): #计算方差
sdev = 0.0
for num in numbers:
sdev = sdev + (num - mean)**2
return pow(sdev / (len(numbers)-1), 0.5) if __name__ == '__main__':
mze_array=[]
mae_array=[]
mse_array=[]
trainfile = "test_housing.0"
testfile = "train_housing.0"
X_train0, y_train = load_svmlight_file(trainfile)
X_test0 , y_test = load_svmlight_file(testfile)
X_train = X_train0.todense()
X_test = X_test0.todense()
attribute = np.shape(X_train)[-1]#tf.shape(X_train)
n_class = tf.reduce_max(y_train)
print("n_class:", n_class) X_train, y_train = shuffle(X_train, y_train, random_state=0)
y_train = y_train - 1
y_test = y_test - 1
clf = MLPClassifier(attribute, 5, [100]*3)
log = clf.fit(X_train, y_train, n_epoch=1000, keep_prob=0.8, val_data=(X_test, y_test))
Y_pred = clf.predict(X_test)
mze = 1- (Y_pred == y_test).mean()
mae = np.abs(Y_pred.ravel()-y_test.ravel()).astype(float).mean()
mse = np.power(Y_pred.ravel()-y_test.ravel(),2).astype(float).mean()
print("mze: %.4f" % mze)
print("mae:", mae)
print("mse:", mse)
Rudolf Wille. Restructuring lattice theory: An approach based on hierarchies of concepts. In Sébastien Ferré andSebastian Rudolph, editors,Formal Concept Analysis, pages 314–339, Berlin, Heidelberg, 2009. Springer BerlinHeidelberg.
R. Wille. Restructuring lattice theory: An approach based on hierarchies of concepts. In
I. Rival, editor, Ordered Sets, pages 445–470. Reidel, Dordrecht-Boston, 1982.
mlp_clf_mnist_test的更多相关文章
随机推荐
- springboot集成themeleaf报Namespace 'th' is not bound
<!DOCTYPE html><!--解决th报错 --><html lang="en" xmlns:th="http://www.w3.o ...
- 选择排序java实现
package text.algorithm; /** * 选择排序 * O(n^2);空间复杂度O(1); */public class SelectionSort { public static ...
- CCF CSP 201509-1 数列分段
题目链接:http://118.190.20.162/view.page?gpid=T32 问题描述 试题编号: 201509-1 试题名称: 数列分段 时间限制: 1.0s 内存限制: 256.0M ...
- 2.4JAVA基础复习——JAVA语言的基础组成数组
JAVA语言的基础组成有: 1.关键字:被赋予特殊含义的单词. 2.标识符:用来标识的符号. 3.注释:用来注释说明程序的文字. 4.常量和变量:内存存储区域的表示. 5.运算符:程序中用来运算的符号 ...
- pyautogui
pip install PyGetWindow==0.0.1 pip install pyautogui https://www.cnblogs.com/dcb3688/p/4607980.html
- 【模板】ST表
给定一个长度为 \(N\) 的数列,和 \(M\) 次询问,求出每一次询问的区间\([l,r]\)内数字的最大值. 说明 对于30%的数据,满足: \(1 \leq N, M \leq 10 , 1≤ ...
- Pandas截取列部分字符,并据此修改另一列的数据
#截取'股票代码'第一个字符 df['首字符'] = df['股票代码'].str[0:1] ' # 根据'首字符'列的值,修改'市场'的值. 1表示上海 截取字符串的部分字符: date=today ...
- Angular 中的数据交互(get jsonp post)
Angular get 请求数据 Angular5.x 以后 get.post 和和服务器交互使用的是 HttpClientModule 模块. import {HttpClientModule} f ...
- 有关this
this是Javascript函数内部的一个特殊对象,引用的是函数运行时的环境对象,也就是说,this是动态的(箭头函数除外),是在运行时进行绑定的,并不是在编写时绑定(箭头函数是编写时绑定). th ...
- Flask Web框架
Flask依赖两个外部库:Werkzeug和Jinja2.Werkzeug是一个WSGI(在Web应用和多种服务器之间的标准Python接口)工具集:Jinja2负责渲染模板.所以在安装Flask之前 ...