예제 #1
0
def train_project():
    static_data = write_database()

    project_train_manager = ProjectsTrainManager(static_data)
    for _ in range(3):
        # try:
        project_train_manager.fit()
def test_fs_permute(cvs, X_test1, y_test1, cluster_dir):

    logger = logging.getLogger('log_rbf_cnn_test.log')
    logger.setLevel(logging.INFO)
    handler = logging.FileHandler(
        os.path.join(cluster_dir, 'log_rbf_cnn_test.log'), 'a')
    handler.setLevel(logging.INFO)

    # create a logging format
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)

    # add the handlers to the logger
    logger.addHandler(handler)

    rated = None

    static_data = write_database()

    logger.info('Permutation Evaluation')
    logger.info('/n')
    method = 'svm'
    model_sklearn = sklearn_model(cluster_dir, rated, method,
                                  static_data['sklearn']['njobs'])
    model_sklearn.train(cvs)
    pred = model_sklearn.predict(X_test1)

    metrics_svm = model_sklearn.compute_metrics(pred, y_test1, rated)
    logger.info('before feature selection metrics')
    logger.info('sse, %s rms %s, mae %s, mse %s', *metrics_svm)

    fs = FS(cluster_dir, static_data['sklearn']['njobs'])
    features = fs.fit(cvs)
    logger.info('Number of variables %s', str(features.shape[0]))

    for i in range(3):
        cvs[i][0] = cvs[i][0][:, features]
        cvs[i][2] = cvs[i][2][:, features]
        cvs[i][4] = cvs[i][4][:, features]

    model_sklearn = sklearn_model(cluster_dir, rated, method,
                                  static_data['sklearn']['njobs'])
    model_sklearn.train(cvs)
    pred = model_sklearn.predict(X_test1[:, features])

    metrics_svm = model_sklearn.compute_metrics(pred, y_test1, rated)
    logger.info('After feature selection metrics')
    logger.info('sse, %s rms %s, mae %s, mse %s', *metrics_svm)
예제 #3
0
def prepare_data():
    static_data = write_database()

    project_data_manager = ProjectsDataManager(static_data, is_test=False)

    nwp_response = project_data_manager.nwp_extractor()
    if nwp_response == 'Done':
        data_response = project_data_manager.create_datasets()
    else:
        raise RuntimeError('Something was going wrong with NWP extractor')

    if data_response == 'Done':
        project_data_manager.create_projects_relations()
    else:
        raise RuntimeError('Something was going wrong with data manager')

    if hasattr(project_data_manager, 'data_eval'):
        project_data_manager = ProjectsDataManager(static_data, is_test=True)
        nwp_response = project_data_manager.nwp_extractor()
        if nwp_response == 'Done':
            _ = project_data_manager.create_datasets()
        else:
            raise RuntimeError(
                'Something was going wrong with NWP extractor on evaluation')
    def save(self):
        f = open(os.path.join(self.path_model, 'manager' + '.pickle'), 'wb')
        dict = {}
        for k in self.__dict__.keys():
            if k not in [
                    'logger', 'db', 'path_model', 'static_data', 'thres_act',
                    'thres_split', 'use_db'
            ]:
                dict[k] = self.__dict__[k]
        pickle.dump(dict, f)
        f.close()


if __name__ == '__main__':
    from util_database import write_database
    from Fuzzy_clustering.ver_tf2.Projects_train_manager import ProjectsTrainManager

    static_data = write_database()
    project_manager = ProjectsTrainManager(static_data)
    project_manager.initialize()
    project_manager.create_datasets()
    project_manager.create_projects_relations()
    project = [
        pr for pr in project_manager.group_static_data if pr['_id'] == 'Lach'
    ][0]
    static_data = project['static_data']

    model = ModelTrainManager(static_data['path_model'])
    model.init(project['static_data'], project_manager.data_variables)
    model.train()
예제 #5
0
def backup_project():
    static_data = write_database()

    project_backup_manager = ProjectsTrainManager(static_data)
    project_backup_manager.clear_backup_projects()
예제 #6
0
def eval_project():
    static_data = write_database()

    project_eval_manager = ProjectsEvalManager(static_data)
    project_eval_manager.evaluate()
def test_skopt(cvs, X_test1, y_test1, cluster_dir):

    logger = logging.getLogger('log_rbf_cnn_test.log')
    logger.setLevel(logging.INFO)
    handler = logging.FileHandler(
        os.path.join(cluster_dir, 'log_rbf_cnn_test.log'), 'a')
    handler.setLevel(logging.INFO)

    # create a logging format
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)

    # add the handlers to the logger
    logger.addHandler(handler)

    rated = None

    static_data = write_database()

    logger.info('Scikit Optimize Evaluation')
    logger.info('/n')
    logger.info('/n')
    logger.info('SVM train')
    method = 'svm'
    model_sklearn = sklearn_model(cluster_dir, rated, method,
                                  static_data['sklearn']['njobs'])
    if model_sklearn.istrained == True:
        model_sklearn.istrained = False
    model_sklearn.train(cvs)
    pred = model_sklearn.predict(X_test1)

    logger.info('Best params')
    logger.info(model_sklearn.best_params)
    logger.info('Final mae %s', str(model_sklearn.acc_test))
    logger.info('Final total %s', str(model_sklearn.accuracy))

    metrics_svm = model_sklearn.compute_metrics(pred, y_test1, rated)
    logger.info('SVM metrics')
    logger.info('sse, %s rms %s, mae %s, mse %s', *metrics_svm)

    logger.info('finish train for model %s', model_sklearn.model_type)

    logger.info('/n')

    logger.info('nu-SVM train')
    method = 'nusvm'
    model_sklearn = sklearn_model(cluster_dir, rated, method,
                                  static_data['sklearn']['njobs'])
    if model_sklearn.istrained == True:
        model_sklearn.istrained = False
    model_sklearn.train(cvs)
    pred = model_sklearn.predict(X_test1)

    logger.info('Best params')
    logger.info(model_sklearn.best_params)
    logger.info('Final mae %s', str(model_sklearn.acc_test))
    logger.info('Final total %s', str(model_sklearn.accuracy))

    metrics_svm = model_sklearn.compute_metrics(pred, y_test1, rated)
    logger.info('nu-SVM metricsv')
    logger.info('sse, %s rms %s, mae %s, mse %s', *metrics_svm)
    logger.info('finish train for model %s', model_sklearn.model_type)
    logger.info('/n')

    logger.info('XGB train')
    method = 'xgb'
    model_sklearn = sklearn_model(cluster_dir, rated, method,
                                  static_data['sklearn']['njobs'])
    if model_sklearn.istrained == True:
        model_sklearn.istrained = False
    model_sklearn.train(cvs)
    pred = model_sklearn.predict(X_test1)

    logger.info('Best params')
    logger.info(model_sklearn.best_params)
    logger.info('Final mae %s', str(model_sklearn.acc_test))
    logger.info('Final total %s', str(model_sklearn.accuracy))

    metrics_xgb = model_sklearn.compute_metrics(pred, y_test1, rated)
    logger.info('Xboost metrics')
    logger.info('sse, %s rms %s, mae %s, mse %s', *metrics_xgb)
    logger.info('finish train for model %s', model_sklearn.model_type)
    logger.info('/n')

    logger.info('RF train')
    method = 'RF'
    model_sklearn = sklearn_model(cluster_dir, rated, method,
                                  static_data['sklearn']['njobs'])
    if model_sklearn.istrained == True:
        model_sklearn.istrained = False
    model_sklearn.train(cvs)
    pred = model_sklearn.predict(X_test1)

    logger.info('Best params')
    logger.info(model_sklearn.best_params)
    logger.info('Final mae %s', str(model_sklearn.acc_test))
    logger.info('Final total %s', str(model_sklearn.accuracy))

    metrics_mlp = model_sklearn.compute_metrics(pred, y_test1, rated)
    logger.info('RF metrics')
    logger.info('sse, %s rms %s, mae %s, mse %s', *metrics_mlp)
    logger.info('/n')
    logger.info('finish train for model %s', model_sklearn.model_type)
    logger.info('MLP train')
    method = 'mlp'
    model_sklearn = sklearn_model(cluster_dir, rated, method,
                                  static_data['sklearn']['njobs'])
    if model_sklearn.istrained == True:
        model_sklearn.istrained = False
    model_sklearn.train(cvs)
    pred = model_sklearn.predict(X_test1)

    logger.info('Best params')
    logger.info(model_sklearn.best_params)
    logger.info('Final mae %s', str(model_sklearn.acc_test))
    logger.info('Final total %s', str(model_sklearn.accuracy))

    metrics_mlp = model_sklearn.compute_metrics(pred, y_test1, rated)
    logger.info('MLP metrics')
    logger.info('sse, %s rms %s, mae %s, mse %s', *metrics_mlp)
    logger.info('finish train for model %s', model_sklearn.model_type)
    logger.info('/n')