import numpy as np
from sklearn import datasets
from sklearn.cross_validation import train_test_split
from chainer import cuda

import skchainer as skc

# cuda.init()

digits = datasets.load_digits()
X = digits.data.astype(np.float32)
y = digits.target.astype(np.int32)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)

tuned_parameters = [
    {'opt_type': ['sgd'],      'opt_lr': [0.01, 0.001], 'net_hidden': [50, 100, 200, 300]},
    {'opt_type': ['adagrad'],  'opt_lr': [0.01, 0.001], 'net_hidden': [50, 100, 200, 300]},
    {'opt_type': ['adam'],                              'net_hidden': [50, 100, 200, 300]}
]
model = skc.LogisticRegressionEstimator(epochs=50, net_out=10, threshold=1e-6)

skc.grid_search(model, tuned_parameters, X_train, y_train, X_test, y_test, score='accuracy')
digits = datasets.load_digits()
X = digits.data.astype(np.float32)
y = digits.target.astype(np.int32)
X_train, X_test, y_train, y_test = train_test_split(X,
                                                    y,
                                                    test_size=0.3,
                                                    random_state=0)

tuned_parameters = [{
    'opt_type': ['sgd'],
    'opt_lr': [0.01, 0.001],
    'net_hidden': [50, 100, 200, 300]
}, {
    'opt_type': ['adagrad'],
    'opt_lr': [0.01, 0.001],
    'net_hidden': [50, 100, 200, 300]
}, {
    'opt_type': ['adam'],
    'net_hidden': [50, 100, 200, 300]
}]
model = skc.LogisticRegressionEstimator(epochs=50, net_out=10, threshold=1e-6)

skc.grid_search(model,
                tuned_parameters,
                X_train,
                y_train,
                X_test,
                y_test,
                score='accuracy')
Example #3
0
parser.add_argument('--n_jobs',     type=int, default=-1)
parser.add_argument('--n_iter',     type=int, default=10)
parser.add_argument('--gpu',        type=int, default=-1)
parser.add_argument('--epochs',     type=int, default=1)
args = parser.parse_args()

model = skc.RNNCharEstimator(epochs=args.epochs, vocab_size=len(vocab), threshold=1e-6)

if args.mode == 'grid':
    tuned_parameters = [
        {'net_type':   ['irnn'],
         'opt_type':   ['adam'],
         'opt_lr':     [0.01],
         'net_hidden': [200],
         'batch_size': [3, 4, 5, 6, 8, 10, 15],
         'gpu':        [args.gpu]}
    ]
    skc.grid_search(model, tuned_parameters, X_train, y_train, X_test, y_test, score='accuracy', n_jobs=args.n_jobs)

elif args.mode == 'random':
    tuned_parameters = {
        'net_type': ['irnn'], 'opt_type': ['adam', 'adagrad'], 'net_hidden': sp.stats.norm(300, 100)
    }
    skc.random_search(model, tuned_parameters, X_train, y_train, X_test, y_test, score='accuracy', n_jobs=args.n_jobs, n_iter=args.n_iter)

elif args.mode == 'time':
    print("hello")

# predict -----------------------
# print model.predict(X[1:5,])