Exemplo n.º 1
0
    logger.info(f'Splitting data set:')
    train_frac, val_frac, test_frac = args.train_val_test_frac
    X_train, X_val_test, y_train, y_val_test = model_selection.train_test_split(
        samples,
        encoded_labels,
        test_size=val_frac + test_frac,
        random_state=RANDOM_SEED,
        shuffle=True)
    val_split = int(len(X_val_test) * val_frac / (val_frac + test_frac))
    X_val, y_val = X_val_test[:val_split], y_val_test[:val_split]
    X_test, y_test = X_val_test[val_split:], y_val_test[val_split:]
    logger.info(f'...training samples: {len(X_train)}')
    logger.info(f'...validation samples: {len(X_val)}')
    logger.info(f'...test samples: {len(X_test)}')

    proj_mask = common.ProjMask(*args.proj_mask)
    logger.info(f'Projection mask: {proj_mask}')
    logger.info(f'Augment epochs: {args.epochs}')
    logger.info(f'Online learning: {args.online_learn}')

    if not args.use_svc:
        logger.info('Using SVM algo: SGDClassifier.')
        clf = sgd_fit(train=(X_train, y_train),
                      test=(X_test, y_test),
                      proj_mask=args.proj_mask,
                      online_learn=args.online_learn,
                      svm_model=args.svm_model,
                      epochs=args.epochs)
    else:
        logger.info('Using SVM algo: SVC.')
        clf = svc_fit(train=(X_train, y_train),
Exemplo n.º 2
0
from sys import maxsize as SYS_MAXSIZE

#np.set_printoptions(threshold=SYS_MAXSIZE)

# Output SVM confusion matrix name.
SVM_CM = 'train-results/svm_cm.png'
# Output XGBoost confusion matrix name.
XGB_CM = 'train-results/xgb_cm.png'
# Define a seed so random operations are the same from run to run.
RANDOM_SEED = 1234
# Define number of folds for the Stratified K-Folds cross-validator.
FOLDS = 5
# Number of parameters to combine for xgb random search.
PARA_COMB = 20
# Radar 2-D projections to use for predictions.
PROJ_MASK = common.ProjMask(xy=True, xz=True, yz=True)


def evaluate_model(model, X_test, y_test, target_names, cm_name):
    """ Generate model confusion matrix and classification report. """
    print('\n Evaluating model.')
    y_pred = model.predict(X_test)
    cm = confusion_matrix(y_test, y_pred)
    print(f'\n Confusion matrix:\n{cm}')
    cm_figure = plot_confusion_matrix(cm, class_names=target_names)
    cm_figure.savefig(path.join(common.PRJ_DIR, cm_name))
    cm_figure.clf()
    print('\n Classification matrix:')
    print(classification_report(y_test, y_pred, target_names=target_names))
    return
Exemplo n.º 3
0
from sklearn import svm, linear_model

logger = logging.getLogger(__name__)

# Radar detection threshold.
RADAR_THRESHOLD = 5
# Set to True if using Moving Target Identification (MTI) filter.
MTI = True
# Radar scan arena in polar coords.
# This can be different than arena used for training.
R_MIN, R_MAX, R_RES = 10, 360, 2
THETA_MIN, THETA_MAX, THETA_RES = -42, 42, 4
PHI_MIN, PHI_MAX, PHI_RES = -30, 30, 2

# Radar 2-D projections to use for predictions.
PROJ_MASK = common.ProjMask(xy=True, xz=True, yz=True)

LOG_FILE = 'predict.log'


def calc_proj_zoom(train_size_x, train_size_y, train_size_z, size_x, size_y,
                   size_z):
    """ Calculate projection zoom factors for prediction radar arena.

    Args:
        train_size_{x,y,z} (int): Size of image array used for training.
        size_{x,y,z} (int): Size of sample image array.

    Returns:
        ProjZoom (tuple of list of floats): Zoom factors per projection.
    """