Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import nni
params = nni.get_next_parameter()
print('params:', params)
x = params['x']
nni.report_final_result(x)
return model
def run(X_train, X_test, y_train, y_test, model):
'''Train model and predict result'''
model.fit(X_train, y_train)
score = model.score(X_test, y_test)
LOG.debug('score: %s' % score)
nni.report_final_result(score)
if __name__ == '__main__':
X_train, X_test, y_train, y_test = load_data()
try:
# get parameters from tuner
RECEIVED_PARAMS = nni.get_next_parameter()
LOG.debug(RECEIVED_PARAMS)
PARAMS = get_default_parameters()
PARAMS.update(RECEIVED_PARAMS)
LOG.debug(PARAMS)
model = get_model(PARAMS)
run(X_train, X_test, y_train, y_test, model)
except Exception as exception:
LOG.exception(exception)
raise
SendMetrics(),
EarlyStopping(min_delta=0.001, patience=10),
TensorBoard(log_dir=TENSORBOARD_DIR),
],
)
# trial report final acc to tuner
_, acc = net.evaluate(x_test, y_test)
logger.debug("Final result is: %.3f", acc)
nni.report_final_result(acc)
if __name__ == "__main__":
try:
# trial get next parameter from network morphism tuner
RCV_CONFIG = nni.get_next_parameter()
logger.debug(RCV_CONFIG)
parse_rev_args(RCV_CONFIG)
train_eval()
except Exception as exception:
logger.exception(exception)
raise
from sklearn.preprocessing import LabelEncoder
sys.path.append('../../')
from fe_util import *
from model import *
logger = logging.getLogger('auto-fe-examples')
if __name__ == '__main__':
file_name = '~/Downloads/haberman.data'
target_name = 'Label'
id_index = 'Id'
# get parameters from tuner
RECEIVED_PARAMS = nni.get_next_parameter()
logger.info("Received params:\n", RECEIVED_PARAMS)
# list is a column_name generate from tuner
df = pd.read_csv(file_name, sep = ',')
df.columns = [
'c1', 'c2', 'n1', 'Label'
]
df['Label'] = df['Label'] -1 #LabelEncoder().fit_transform(df['Label'])
if 'sample_feature' in RECEIVED_PARAMS.keys():
sample_col = RECEIVED_PARAMS['sample_feature']
else:
sample_col = []
# raw feaure + sample_feature
df = name2feature(df, sample_col, target_name)
if layer_name == 'Empty':
# Empty Layer
params[key] = ['Empty']
elif layer_name == 'Conv':
# Conv layer
params[key] = [layer_name, value['kernel_size'], value['kernel_size']]
else:
# Pooling Layer
params[key] = [layer_name, value['pooling_size'], value['pooling_size']]
return params
if __name__ == '__main__':
try:
# get parameters form tuner
data = nni.get_next_parameter()
logger.debug(data)
RCV_PARAMS = parse_init_json(data)
logger.debug(RCV_PARAMS)
params = vars(get_params())
params.update(RCV_PARAMS)
print(RCV_PARAMS)
main(params)
except Exception as exception:
logger.exception(exception)
raise
# predict
y_pred = gbm.predict(X_test, num_iteration=gbm.best_iteration)
# eval
rmse = mean_squared_error(y_test, y_pred) ** 0.5
print('The rmse of prediction is:', rmse)
nni.report_final_result(rmse)
if __name__ == '__main__':
lgb_train, lgb_eval, X_test, y_test = load_data()
try:
# get parameters from tuner
RECEIVED_PARAMS = nni.get_next_parameter()
LOG.debug(RECEIVED_PARAMS)
PARAMS = get_default_parameters()
PARAMS.update(RECEIVED_PARAMS)
LOG.debug(PARAMS)
# train
run(lgb_train, lgb_eval, PARAMS, X_test, y_test)
except Exception as exception:
LOG.exception(exception)
raise
from sklearn.preprocessing import LabelEncoder
sys.path.append('../../')
from fe_util import *
from model import *
logger = logging.getLogger('auto-fe-examples')
if __name__ == '__main__':
file_name = ' ~/Downloads/breast-cancer.data'
target_name = 'Class'
id_index = 'Id'
# get parameters from tuner
RECEIVED_PARAMS = nni.get_next_parameter()
logger.info("Received params:\n", RECEIVED_PARAMS)
# list is a column_name generate from tuner
df = pd.read_csv(file_name, sep = ',')
df.columns = [
'Class', 'age', 'menopause', 'tumor-size', 'inv-nodes',
'node-caps', 'deg-malig', 'breast', 'breast-quad', 'irradiat'
]
df['Class'] = LabelEncoder().fit_transform(df['Class'])
if 'sample_feature' in RECEIVED_PARAMS.keys():
sample_col = RECEIVED_PARAMS['sample_feature']
else:
sample_col = []
# raw feaure + sample_feature
SendMetrics(),
EarlyStopping(min_delta=0.001, patience=10),
TensorBoard(log_dir=TENSORBOARD_DIR),
],
)
# trial report final acc to tuner
_, acc = net.evaluate(x_test, y_test)
logger.debug("Final result is: %.3f", acc)
nni.report_final_result(acc)
if __name__ == "__main__":
try:
# trial get next parameter from network morphism tuner
RCV_CONFIG = nni.get_next_parameter()
logger.debug(RCV_CONFIG)
parse_rev_args(RCV_CONFIG)
train_eval()
except Exception as exception:
logger.exception(exception)
raise
'learning_rate': 0.001
}
if __name__ == '__main__':
PARSER = argparse.ArgumentParser()
PARSER.add_argument("--batch_size", type=int, default=200, help="batch size", required=False)
PARSER.add_argument("--epochs", type=int, default=10, help="Train epochs", required=False)
PARSER.add_argument("--num_train", type=int, default=60000, help="Number of train samples to be used, maximum 60000", required=False)
PARSER.add_argument("--num_test", type=int, default=10000, help="Number of test samples to be used, maximum 10000", required=False)
ARGS, UNKNOWN = PARSER.parse_known_args()
try:
# get parameters from tuner
# RECEIVED_PARAMS = {"optimizer": "Adam", "learning_rate": 0.00001}
RECEIVED_PARAMS = nni.get_next_parameter()
LOG.debug(RECEIVED_PARAMS)
PARAMS = generate_default_params()
PARAMS.update(RECEIVED_PARAMS)
# train
train(ARGS, PARAMS)
except Exception as e:
LOG.exception(e)
raise