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的更多相关文章

随机推荐

  1. 示例, linq分组

    public class HIS_CLIREGISTER : BaseModel{ private String _FBCODE;[StringLength(8)]/// <summary> ...

  2. C#返回字符串的字节长度,一个中文算两个字符的代码

    如下代码段是关于C#返回字符串的字节长度,一个中文算两个字符的代码. public static int GetLength(string str) { if (str.Length == 0) re ...

  3. 问题 1923: [蓝桥杯][算法提高VIP]学霸的迷宫 (BFS)

    题目链接:https://www.dotcpp.com/oj/problem1923.html 题目描述 学霸抢走了大家的作业,班长为了帮同学们找回作业,决定去找学霸决斗.但学霸为了不要别人打扰,住在 ...

  4. 1344:【例4-4】最小花费 dijkstra

    1344:[例4-4]最小花费 Dijkstra (1)a [ i ] [ j ] 存转账率(..转后所得率..) (2)dis [ i ] 也就是 a [ 起点 ] [ i ] (3)f [ i ] ...

  5. python源码为何都是pass

    最近看Python代码  按照一个函数递进的看下去,最后发现,遇到很多源码什么逻辑都没写,仅仅以一个pass  结尾          但却能得到应该得到的结果,这点真的很奇怪,上网查找后 觉得下面的 ...

  6. 使用session和cookie实现用户登录:一个登录页面,一个servlet,一个登录成功页面

    文件目录 1.登录页面 <%@ page language="java" contentType="text/html; charset=utf-8" p ...

  7. laravel中ajax,post传值问题

    //laravel中有CSRF保护 不加的话会出现419错误$.ajax({ url: '/admin/user/'+id, type: "POST", data: {'_toke ...

  8. Servlet3.0与springmvc那些事

    官方文档:https://docs.spring.io/spring/docs/5.0.2.RELEASE/spring-framework-reference/web.html#mvc-servle ...

  9. Navicat Premium 12

    1.win 客户端软件下载: https://www.navicat.com.cn/download/navicat-premium 2.安装 双击安装--点击下一步 我同意--下一步 选择安装路径- ...

  10. 2019-4-23 plan

    需要制作springcloud es6的技术文档和demo