zoukankan      html  css  js  c++  java
  • 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.
  • 相关阅读:
    LIKE语句也可以这样写
    a链接触发javascript函数导致innerHTML里的图片无法加载
    引用类型真屌
    网站建设心得
    SPAN
    Go! 环境配置和入门
    linux内核编译
    面试题
    KCMT开源控件之方便简洁的分页控件
    c#中out、ref和params的用法与区别
  • 原文地址:https://www.cnblogs.com/huadongw/p/10389332.html
Copyright © 2011-2022 走看看