def test_open_model(): """ Test neoruanalyzer.open_model function """ reg = neuroanalyzer.AgeRegressor() reg.open_model(settings.project_folder + '/' + settings.neural_network_file) assert 1 == 1, "It should not give any exceptions" # Passed if there will be no exception, so it is okay
def test_train_with_raw_data(): """ Test neuroanalyzer.train_with_raw_data() function :return: """ reg = neuroanalyzer.AgeRegressor() reg.train_with_raw_data([], True) # Passed if there will be no exception, so it is okay assert 1 == 1, "It should not give any exceptions"
def test_query(): """ Test neoruanalyzer.query function """ reg = neuroanalyzer.AgeRegressor() reg.open_model(settings.project_folder + '/' + settings.neural_network_file) predicted = reg._query( [21, 21, 21, 24, 24, 51, 51, 24, 17, 16, 16, 22, 91, 91, 91, 21, 15, 15, 25, 15, 14, 35, 34, 20, 20, 28, 15, 16, 20, 15, 24, 47, 25, 15, 16]) assert abs(15 - predicted) <= 1, "Should be 15±1"
def test_train_with_raw_data(): """ Test neuroanalyzer.train_with_raw_data() function :return: """ reg = neuroanalyzer.AgeRegressor() df_raw = pd.read_csv(settings.project_folder + '/' + 'tests/age_research1.csv') reg.train_with_raw_data(df_raw) # Passed if there will be no exception, so it is okay assert 1 == 1, "It should not give any exceptions"
def test_estimate_age_recursive(target, expected, deviation): """Test tg.estimate_age_recursive function :param target: Target, whom to analyze :param expected: expected answer :param deviation: Allowed deviation |expected-answer| <= deviation :return: Asserts True if it was correct """ model = neuroanalyzer.AgeRegressor() model.open_model('neuronet.sav') estimated_age = telegram_bot.estimate_age_recursive(target, model) if expected == -1: assert estimated_age == expected assert abs(estimated_age - expected) <= deviation
def set_real_age(domain, real_age, verify): """ Set person's real age """ target_id = age_analyzer.get_id_by_domain(domain) domain = age_analyzer.get_domain_by_id(target_id) model = neuroanalyzer.AgeRegressor() model.open_model('neuronet.sav') analyze_and_insert(domain, model, force_upgrade=True) connection = psycopg2.connect(database=settings.db_name, user=settings.db_login, password=settings.db_pass, host=settings.db_ip, port=settings.db_port) cur = connection.cursor() cur.executescript( f"UPDATE analyzed SET real_age = %s WHERE id = \'%s\';" f"UPDATE analyzed SET verified = %s WHERE id = \'%s\';", [real_age, target_id, verify, target_id]) connection.commit() connection.close()
if __name__ == "__main__": ANALYZE = True # Set it by yourself BOT = False FILL_CSV = False TRAIN_MODEL = False TRAIN_MODEL_WITH_TABLE = False FILL_TABLE = False FILL_TABLE_RECURSIVE = False if FILL_CSV: df = pd.read_csv('age_research.csv') df = csv_connect.fill_friends_age(df) df = csv_connect.fill_vk_age(df) df.fillna(-1.0, inplace=True) df.to_csv('age_research1.csv', index=False) if TRAIN_MODEL: model = neuroanalyzer.AgeRegressor() if not TRAIN_MODEL_WITH_TABLE: df = pd.read_csv('age_research1.csv') model.train_with_raw_data(df, False) else: model.train_with_raw_data([], True) model.save_model('neuronet.sav') if FILL_TABLE: df = pd.read_csv('age_research1.csv') model = neuroanalyzer.AgeRegressor() model.open_model('neuronet.sav') for i in range(len(df)): now_target = df['ID'][i] try: model.query(now_target, False, False) postgres_report.set_real_age(now_target, df['Real Age'][i],
import logging import matplotlib.pyplot as plt import numpy as np import pandas as pd import telebot import age_analyzer import neuroanalyzer import settings from age_analyzer import find_max_mode from neuroanalyzer import AgeRegressor bot = telebot.TeleBot(settings.tg_api) neural_network: AgeRegressor = neuroanalyzer.AgeRegressor() def counts_by_arr(arr: np.ndarray) -> np.ndarray: """ This fucntion returns array with count of each element. A[j] = count of j meetings in input :param arr: List :return: """ answ_arr = list([0] * (max(arr) + 1)) for i in arr: answ_arr[i] += 1 return np.array(answ_arr)
def test_analyze_and_insert(target, force_upgrade): model = neuroanalyzer.AgeRegressor() model.open_model('neuronet.sav') postgres_report.analyze_and_insert(target=target, force_upgrade=force_upgrade, model=model) assert True
def test_init(): reg = neuroanalyzer.AgeRegressor() reg.__init__() assert 1 == 1, "It should not give any exceptions"
def test_analyze_recursive(message): model = neuroanalyzer.AgeRegressor() model.open_model('neuronet.sav') assert telegram_bot.analyze_recursive(message, True, model) == message.chat.id