import numpy as np import matplotlib.pyplot as plt import ml (X_train, T_train), (X_test, T_test) = ml.load_data('mnist') ae = ml.feature.autoencoder.fit(X_train, [128, 64, 32], encode_act='ReLU', decode_act=['sigmoid', 'ReLU', 'ReLU'], X_val=X_test, eta0=0.0001, optimizer='Momentum', lamb=0.0001, max_epoch=500, patience_epoch=30) ae.save('pkl/ae') ml.imshow(ae(X_train[0]).flatten()) plt.pause(1) ml.imshow(ae(X_test[0]).flatten()) plt.pause(1)
"""コマンドラインから python3 tests/eval_mlp3d.py no_dropout または python3 tests/eval_mlp3d.py dropout と実行 """ import ml, numpy as np, sys (X_train, T_train), (X_test, T_test) = ml.load_data() fnames = { 'no_dropout' : 'pkl/mlp3d.pkl', 'dropout' : 'pkl/mlp3d_dropout_weight_decay.pkl' } which = fnames[sys.argv[1]] net = ml.load(which) net(X_train[:10000]) X = net[-2].z.copy() labels = T_train[:10000] ev_train = ml.evaluate(ml.cluster.as_cluster(X, labels)) print(ev_train) ml.save(ev_train, f'pkl/eval_mlp3d_{sys.argv[1]}_train') net(X_test) X = net[-2].z.copy() labels = T_test
#-------------------------------------------------------------------------------- # Copyright (C) 2015 - 2020 Cloudspindle Inc. # HelloMotion.ipynb: - 'hello world' example for Deep Learning using # - motion data generated from the MeKit platform. # - Learn to classify clockwise and anticlockwise motions # License Terms: # Permission is hereby granted to use this software freely under the terms of # the free bsd license: https://www.freebsd.org/copyright/freebsd-license.html #-------------------------------------------------------------------------------- #!git clone https://github.com/Cloudspindle/helloml.git from ml import init,load_data,show_input_example,define_neural_net,show_input_example,define_neural_net,train_neural_net,test_neural_net input_set_size=100 test_set_size=2 num_samples=200 # 200 samples are in the motion examples # neural network node parameters num_inputs=num_samples # we make the number of neural inputs equal to the number of samples in the motion examples num_hidden=512 num_outputs=2 training_cycles=100 init() #define global variables (input_set,output_set,test_set)=load_data() #load the data (input training, output and test) NB - You manually #now need to load the following files in this order (ClockwiseZero_accel.200.csv, AntiClockwiseZero_accel.200.csv, ChloeClockwise_accel.200.csv, ChloeAntiClock_accel.200.csv). The first two are the training examples from which a full 100 example #training set will be built. The second two and the two examples #that will be tested after training. show_input_example() #show an example of the data (input training v test) - rerun to #randomly select and example net=define_neural_net(num_inputs,num_hidden,num_outputs) #define the neural network train_neural_net(net,training_cycles) #train the neural network test_neural_net(net) #test the neural network with the two test examples (the blue signal line is the clockwise test example and the orange signal line is the anticlockwise test example) #!rm -rf helloml
def test_knn_and_snm(data_file): X, y = ml.load_data(data_file) return test_knn(X, y), test_svm(X, y)