diff --git a/predihood/classes/Dataset.py b/predihood/classes/Dataset.py index b3bbfbf8bfb51b5418bfd62aeb9ed713bd4f0d5c..9e3d24bd7264fda657ac7848b9dae3ce2601369d 100644 --- a/predihood/classes/Dataset.py +++ b/predihood/classes/Dataset.py @@ -2,7 +2,7 @@ import logging import pandas as pd from predihood.config import TRAIN_SIZE, TEST_SIZE, ENVIRONMENT_VARIABLES, RANDOM_STATE, FILE_ENV -from predihood.utility_functions import check_dataset_size +from predihood.utility_functions import check_train_test_percentages from sklearn.ensemble import IsolationForest from sklearn.model_selection import train_test_split @@ -41,7 +41,7 @@ class Dataset: self.Y_test = None if env in ENVIRONMENT_VARIABLES: self.env = env else: self.env = "building_type" - self.train_size, self.test_size = check_dataset_size(train_size, test_size) + self.train_size, self.test_size = check_train_test_percentages(train_size, test_size) self.outliers = outliers def init_all_in_one(self): diff --git a/predihood/classes/manual_assessment.csv b/predihood/classes/manual_assessment.csv index 38e70520a51f57b52e5cb18bdf5132fa2a985eba..a596954497c5ab74bba61cfd2bf94a75a5258a93 100644 --- a/predihood/classes/manual_assessment.csv +++ b/predihood/classes/manual_assessment.csv @@ -1,2 +1 @@ CODE,AREA,DENSITY,P14_POP,P14_POP0002,P14_POP0305,P14_POP0610,P14_POP1117,P14_POP1824,P14_POP2539,P14_POP4054,P14_POP5564,P14_POP6579,P14_POP80P,P14_POP0014,P14_POP1529,P14_POP3044,P14_POP4559,P14_POP6074,P14_POP75P,P14_POP0019,P14_POP2064,P14_POP65P,P14_POPH,P14_H0014,P14_H1529,P14_H3044,P14_H4559,P14_H6074,P14_H75P,P14_H0019,P14_H2064,P14_H65P,P14_POPF,P14_F0014,P14_F1529,P14_F3044,P14_F4559,P14_F6074,P14_F75P,P14_F0019,P14_F2064,P14_F65P,C14_POP15P,C14_POP15P_CS1,C14_POP15P_CS2,C14_POP15P_CS3,C14_POP15P_CS4,C14_POP15P_CS5,C14_POP15P_CS6,C14_POP15P_CS7,C14_POP15P_CS8,C14_H15P,C14_H15P_CS1,C14_H15P_CS2,C14_H15P_CS3,C14_H15P_CS4,C14_H15P_CS5,C14_H15P_CS6,C14_H15P_CS7,C14_H15P_CS8,C14_F15P,C14_F15P_CS1,C14_F15P_CS2,C14_F15P_CS3,C14_F15P_CS4,C14_F15P_CS5,C14_F15P_CS6,C14_F15P_CS7,C14_F15P_CS8,P14_POP_FR,P14_POP_ETR,P14_POP_IMM,P14_PMEN,P14_PHORMEN,P14_LOG,P14_RP,P14_RSECOCC,P14_LOGVAC,P14_MAISON,P14_APPART,P14_RP_1P,P14_RP_2P,P14_RP_3P,P14_RP_4P,P14_RP_5PP,P14_NBPI_RP,P14_RPMAISON,P14_NBPI_RPMAISON,P14_RPAPPART,P14_NBPI_RPAPPART,P14_RP_M30M2,P14_RP_3040M2,P14_RP_4060M2,P14_RP_6080M2,P14_RP_80100M2,P14_RP_100120M2,P14_RP_120M2P,P14_RP_ACHTOT,P14_RP_ACH19,P14_RP_ACH45,P14_RP_ACH70,P14_RP_ACH90,P14_RP_ACH05,P14_RP_ACH11,P14_RPMAISON_ACHTOT,P14_RPMAISON_ACH19,P14_RPMAISON_ACH45,P14_RPMAISON_ACH70,P14_RPMAISON_ACH90,P14_RPMAISON_ACH05,P14_RPMAISON_ACH11,P14_RPAPPART_ACHTOT,P14_RPAPPART_ACH19,P14_RPAPPART_ACH45,P14_RPAPPART_ACH70,P14_RPAPPART_ACH90,P14_RPAPPART_ACH05,P14_RPAPPART_ACH11,P14_MEN,P14_MEN_ANEM0002,P14_MEN_ANEM0204,P14_MEN_ANEM0509,P14_MEN_ANEM10P,P14_PMEN_ANEM0002,P14_PMEN_ANEM0204,P14_PMEN_ANEM0509,P14_PMEN_ANEM10P,P14_NBPI_RP_ANEM0002,P14_NBPI_RP_ANEM0204,P14_NBPI_RP_ANEM0509,P14_NBPI_RP_ANEM10P,P14_RP_PROP,P14_RP_LOC,P14_RP_LOCHLMV,P14_RP_GRAT,P14_NPER_RP,P14_NPER_RP_PROP,P14_NPER_RP_LOC,P14_NPER_RP_LOCHLMV,P14_NPER_RP_GRAT,P14_ANEM_RP,P14_ANEM_RP_PROP,P14_ANEM_RP_LOC,P14_ANEM_RP_LOCHLMV,P14_ANEM_RP_GRAT,P14_RP_SDB,P14_RP_CCCOLL,P14_RP_CCIND,P14_RP_CINDELEC,P14_RP_ELEC,P14_RP_EAUCH,P14_RP_BDWC,P14_RP_CHOS,P14_RP_CLIM,P14_RP_TTEGOU,P14_RP_GARL,P14_RP_VOIT1P,P14_RP_VOIT1,P14_RP_VOIT2P,NB_B101,NB_B102,NB_B103,NB_B201,NB_B202,NB_B203,NB_B204,NB_B205,NB_B206,NB_B301,NB_B302,NB_B303,NB_B304,NB_B305,NB_B306,NB_B307,NB_B308,NB_B309,NB_B310,NB_B311,NB_B312,NB_B313,NB_B315,NB_B316,DEC_PIMP14,DEC_TP6014,DEC_Q114,DEC_MED14,DEC_Q314,DEC_EQ14,DEC_D114,DEC_D214,DEC_D314,DEC_D414,DEC_D614,DEC_D714,DEC_D814,DEC_D914,DEC_RD14,DEC_S80S2014,DEC_GI14,DEC_PTSA14,DEC_PCHO14,DEC_PBEN14,DEC_PPEN14,DEC_PAUT14,note,NB_D201,NB_D202,NB_D203,NB_D204,NB_D205,NB_D206,NB_D207,NB_D208,NB_D209,NB_D210,NB_D211,NB_D212,NB_D213,NB_D221,NB_D231,NB_D232,NB_D233,NB_D235,NB_D236,NB_D237,NB_D238,NB_D239,NB_D240,NB_D242,NB_D243,C401,C402,C403,C409,C501,C502,C503,C504,C505,C505_NB_INT,C509,C601,C602,C603,C604,C605,C605_NB_INT,C609,C701,C702,C101,C101_NB_CANT,C101_NB_EP,C101_NB_RPIC,C102,C102_NB_CANT,C102_NB_EP,C104,C104_NB_CANT,C104_NB_PELEM,C104_NB_EP,C104_NB_RPIC,C105,C105_NB_CANT,C105_NB_PELEM,C105_NB_EP,NB_F101,NB_F101_NB_AIREJEU,NB_F101_NB_COU,NB_F101_NB_ECL,NB_F102,NB_F102_NB_AIREJEU,NB_F102_NB_COU,NB_F102_NB_ECL,NB_F103,NB_F103_NB_AIREJEU,NB_F103_NB_COU,NB_F103_NB_ECL,NB_F104,NB_F104_NB_AIREJEU,NB_F104_NB_COU,NB_F104_NB_ECL,NB_F105,NB_F105_NB_AIREJEU,NB_F105_NB_COU,NB_F105_NB_ECL,NB_F106,NB_F106_NB_AIREJEU,NB_F106_NB_COU,NB_F106_NB_ECL,NB_F107,NB_F107_NB_AIREJEU,NB_F107_NB_COU,NB_F107_NB_ECL,NB_F108,NB_F108_NB_AIREJEU,NB_F108_NB_COU,NB_F108_NB_ECL,NB_F109,NB_F109_NB_AIREJEU,NB_F109_NB_COU,NB_F109_NB_ECL,NB_F110,NB_F110_NB_AIREJEU,NB_F110_NB_COU,NB_F110_NB_ECL,NB_F111,NB_F111_NB_AIREJEU,NB_F111_NB_COU,NB_F111_NB_ECL,NB_F112,NB_F112_NB_AIREJEU,NB_F112_NB_COU,NB_F112_NB_ECL,NB_F113,NB_F113_NB_AIREJEU,NB_F113_NB_COU,NB_F113_NB_ECL,NB_F114,NB_F114_NB_AIREJEU,NB_F114_NB_COU,NB_F114_NB_ECL,NB_F116,NB_F116_NB_AIREJEU,NB_F116_NB_COU,NB_F116_NB_ECL,NB_F117,NB_F117_NB_AIREJEU,NB_F117_NB_COU,NB_F117_NB_ECL,NB_F118,NB_F118_NB_AIREJEU,NB_F118_NB_COU,NB_F118_NB_ECL,NB_F119,NB_F119_NB_AIREJEU,NB_F119_NB_COU,NB_F119_NB_ECL,NB_F120,NB_F120_NB_AIREJEU,NB_F120_NB_COU,NB_F120_NB_ECL,NB_F121,NB_F121_NB_AIREJEU,NB_F121_NB_COU,NB_F121_NB_ECL,NB_F201,NB_F201_NB_AIREJEU,NB_F202,NB_F202_NB_AIREJEU,NB_F203,NB_F203_NB_AIREJEU,NB_F302,NB_F302_NB_SALLES,NB_F303,NB_F303_NB_SALLES,NB_F304,NB_F305,NB_A101,NB_A104,NB_A105,NB_A106,NB_A107,NB_A108,NB_A109,NB_A115,NB_A119,NB_A120,NB_A121,NB_A122,NB_A123,NB_A124,NB_A125,NB_A203,NB_A205,NB_A206,NB_A207,NB_A208,NB_A301,NB_A302,NB_A303,NB_A304,NB_A401,NB_A402,NB_A403,NB_A404,NB_A405,NB_A406,NB_A501,NB_A502,NB_A503,NB_A504,NB_A505,NB_A506,NB_A507,P14_POP1564,P14_POP1524,P14_POP2554,P14_H1564,P14_H1524,P14_H2554,P14_H5564,P14_F1564,P14_F1524,P14_F2554,P14_F5564,P14_ACT1564,P14_ACT1524,P14_ACT2554,P14_ACT5564,P14_HACT1564,P14_HACT1524,P14_HACT2554,P14_HACT5564,P14_FACT1564,P14_FACT1524,P14_FACT2554,P14_FACT5564,P14_ACTOCC1564,P14_ACTOCC1524,P14_ACTOCC2554,P14_ACTOCC5564,P14_HACTOCC1564,P14_HACTOCC1524,P14_HACTOCC2554,P14_HACTOCC5564,P14_FACTOCC1564,P14_FACTOCC1524,P14_FACTOCC2554,P14_FACTOCC5564,P14_CHOM1564,P14_CHOM1524,P14_CHOM2554,P14_CHOM5564,P14_HCHOM1564,P14_FCHOM1564,P14_INACT1564,P14_HINACT1564,P14_FINACT1564,P14_ETUD1564,P14_HETUD1564,P14_FETUD1564,P14_RETR1564,P14_HRETR1564,P14_FRETR1564,P14_AINACT1564,P14_HAINACT1564,P14_FAINACT1564,C14_ACT1564,C14_ACT1564_CS1,C14_ACT1564_CS2,C14_ACT1564_CS3,C14_ACT1564_CS4,C14_ACT1564_CS5,C14_ACT1564_CS6,C14_ACTOCC1564,C14_ACTOCC1564_CS1,C14_ACTOCC1564_CS2,C14_ACTOCC1564_CS3,C14_ACTOCC1564_CS4,C14_ACTOCC1564_CS5,C14_ACTOCC1564_CS6,P14_ACTOCC15P,P14_HACTOCC15P,P14_FACTOCC15P,P14_SAL15P,P14_HSAL15P,P14_FSAL15P,P14_NSAL15P,P14_HNSAL15P,P14_FNSAL15P,P14_ACTOCC15P_TP,P14_SAL15P_TP,P14_HSAL15P_TP,P14_FSAL15P_TP,P14_NSAL15P_TP,P14_SAL15P_CDI,P14_SAL15P_CDD,P14_SAL15P_INTERIM,P14_SAL15P_EMPAID,P14_SAL15P_APPR,P14_NSAL15P_INDEP,P14_NSAL15P_EMPLOY,P14_NSAL15P_AIDFAM,P14_ACTOCC15P_ILT1,P14_ACTOCC15P_ILT2P,P14_ACTOCC15P_ILT2,P14_ACTOCC15P_ILT3,P14_ACTOCC15P_ILT4,P14_ACTOCC15P_ILT5,C14_ACTOCC15P,C14_ACTOCC15P_PAS,C14_ACTOCC15P_MAR,C14_ACTOCC15P_DROU,C14_ACTOCC15P_VOIT,C14_ACTOCC15P_TCOM,C201,C201_NB_CANT,C201_NB_EP,C201_NB_INT,C301,C301_NB_CANT,C301_NB_PGE,C301_NB_EP,C301_NB_INT,C302,C302_NB_CANT,C302_NB_PGE,C302_NB_EP,C302_NB_INT,C303,C303_NB_PGE,C303_NB_INT,C304,C304_NB_CANT,C304_NB_INT,C305,C305_NB_CANT,C305_NB_INT,NB_D401,NB_D402,NB_D403,NB_D404,NB_D405,NB_D502,NB_D601,NB_D602,NB_D603,NB_D604,NB_D605,NB_D606,NB_D701,NB_D702,NB_D703,NB_D704,NB_D705,NB_D709,NB_E101,NB_E102,NB_E103,NB_E106,NB_G101,NB_G102,NB_G103,NB_G104,C14_MEN,C14_MENPSEUL,C14_MENHSEUL,C14_MENFSEUL,C14_MENSFAM,C14_MENFAM,C14_MENCOUPSENF,C14_MENCOUPAENF,C14_MENFAMMONO,C14_PMEN,C14_PMEN_MENPSEUL,C14_PMEN_MENHSEUL,C14_PMEN_MENFSEUL,C14_PMEN_MENSFAM,C14_PMEN_MENFAM,C14_PMEN_MENCOUPSENF,C14_PMEN_MENCOUPAENF,C14_PMEN_MENFAMMONO,P14_POP15P,P14_POP5579,P14_POPMEN15P,P14_POPMEN1524,P14_POPMEN2554,P14_POPMEN5579,P14_POPMEN80P,P14_POP15P_PSEUL,P14_POP1524_PSEUL,P14_POP2554_PSEUL,P14_POP5579_PSEUL,P14_POP80P_PSEUL,P14_POP15P_MARIEE,P14_POP15P_NONMARIEE,C14_MEN_CS1,C14_MEN_CS2,C14_MEN_CS3,C14_MEN_CS4,C14_MEN_CS5,C14_MEN_CS6,C14_MEN_CS7,C14_MEN_CS8,C14_PMEN_CS1,C14_PMEN_CS2,C14_PMEN_CS3,C14_PMEN_CS4,C14_PMEN_CS5,C14_PMEN_CS6,C14_PMEN_CS7,C14_PMEN_CS8,C14_FAM,C14_COUPAENF,C14_FAMMONO,C14_COUPSENF,C14_NE24F0,C14_NE24F1,C14_NE24F2,C14_NE24F3,C14_NE24F4P,P14_POP0205,P14_POP1114,P14_POP1517,P14_POP2529,P14_POP30P,P14_SCOL0205,P14_SCOL0610,P14_SCOL1114,P14_SCOL1517,P14_SCOL1824,P14_SCOL2529,P14_SCOL30P,P14_NSCOL15P,P14_NSCOL15P_DIPLMIN,P14_NSCOL15P_CAPBEP,P14_NSCOL15P_BAC,P14_NSCOL15P_SUP,P14_HNSCOL15P,P14_HNSCOL15P_DIPLMIN,P14_HNSCOL15P_CAPBEP,P14_HNSCOL15P_BAC,P14_HNSCOL15P_SUP,P14_FNSCOL15P,P14_FNSCOL15P_DIPLMIN,P14_FNSCOL15P_CAPBEP,P14_FNSCOL15P_BAC,P14_FNSCOL15P_SUP,C15_POP01P_IRAN012,C15_POP01P_IRANAUT,C15_POP01P,building_type,building_usage,landscape,morphological_position,geographical_position,social_class -420590000,21.18203771834871,243.1305273117743,5150.000000000015,157.13757408361502,164.46468719801538,310.11608790816643,435.41398956638886,366.84969227451126,851.5757188090354,1013.7621497340232,577.3174226233151,819.1861471988244,454.1765306041197,880.145514746664,847.5803197544516,926.1247425756692,918.5528076441234,868.3443935337891,709.2522217453176,1157.4206215292377,2719.2167006678333,1273.362677802944,2466.3393023994777,442.8972001418408,439.30944155852615,481.0669711849451,441.4422571843229,412.2980511585516,249.32538117129093,589.2726316093563,1348.0372180232036,529.0294527669174,2683.6606976005373,437.2483146048232,408.27087819592543,445.05777139072416,477.1105504598005,456.0463423752376,459.92684057402664,568.1479899198811,1371.1794826446296,744.3332250360268,4214.731231331136,84.01965627746529,96.12496111789552,195.9701164013495,498.0100658512558,640.7386574709616,827.3422800664333,1425.5106215372523,447.014872608523,1971.652990015908,71.80874001283946,64.10070886898012,136.1691358497115,241.7029564173397,100.08799241378487,621.4738663443387,616.0696868411527,120.2399032677611,2243.078241315228,12.21091626462582,32.0242522489154,59.80098055163801,256.3071094339161,540.6506650571766,205.86841372209457,809.4409346960996,326.7749693407619,5049.691890575002,100.30810942501289,141.18350876782142,5028.000000000016,121.99999999999831,2670.438140556364,2364.0,58.65812591508046,247.78001464128812,1532.470112720375,1130.8638033830307,14.32615580695994,252.9555150502636,574.8405180107106,704.3790314505744,817.4987796814863,9716.808940457167,1393.915573920961,6636.855371672558,963.9915486246122,3062.6632131832207,16.365762982458605,94.240998469549,373.2616924424024,525.2502253578479,665.5775892960804,381.4807764666941,307.8229549849625,2364.0,557.0696986155793,392.659260818259,401.20648926892267,559.5704987806082,315.1000622400652,138.39399027656034,1393.915573920961,328.32989175322945,247.1639235503709,163.87632151263762,329.291596064389,231.6126401782468,93.64120086208712,963.9915486246122,226.7255152305292,145.4953372678881,234.2775968036289,230.2789027162192,82.46140719187358,44.752789414473206,2364.0,257.46648243416854,485.2251506202408,381.9759389697161,1239.3324279758697,504.98588384057393,1057.0724558249367,923.0257545793578,2542.9159057551483,885.8354264578242,1790.0971632300275,1502.8408941202792,5538.035456649037,1312.8642823375994,1005.6215485865524,371.7852630875117,45.51416907584304,5028.000000000016,3126.415876706676,1804.3019352480449,666.3365035477955,97.28218804529592,39546.78684112556,29792.67495131342,9038.8779485887,4692.573876167135,715.2339412234397,2304.1582735649886,240.6662576624528,1680.1230070932115,301.926498461119,,,,,,,1340.3048539022254,1981.6996533631627,1178.3780321733811,803.3216211897816,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2996.4918074504067,553.836516284033,1865.337868543059,1494.412649490719,291.04727296862825,943.3197279750764,260.0456485470146,1502.0791579596876,262.78924331540475,922.0181405679822,317.2717740763005,2290.7317756100506,323.3837593124855,1732.494532796632,234.8534835009329,1216.6908129543554,188.3319475107667,914.1425669267968,114.21629851679198,1074.0409626556952,135.0518118017188,818.3519658698355,120.63718498414092,2101.045237794401,268.2263081987577,1613.216038369903,219.6028912257404,1133.3929357386949,161.3725258029259,862.870817852756,109.14959208301292,967.6523020557062,106.8537823958318,750.3452205171469,110.45329914272745,189.6865378156496,55.1574511137278,119.27849442672922,15.25059227519254,83.29787721566053,106.38866059998902,705.7600318403559,277.7218365363638,428.0381953039925,220.70574698807025,94.79685078883588,125.90889619923433,276.8126685658442,129.62946354149528,147.18320502434892,208.24161628644174,53.295522206032686,154.94609408040907,2333.9466709114463,79.91559679768619,92.07184895247286,195.9701164013495,493.9060063714767,640.7386574709616,823.2382205866543,2144.690109667389,79.91559679768619,92.07184895247286,179.806725543221,449.7199112664536,572.4835976205493,770.6924294870064,2120.4255193572485,1144.5905719991626,975.8349473580862,1856.432834784485,963.5790985148792,892.8537362696059,263.9926845727636,181.01147348428336,82.98121108848025,435.6677059730406,409.5584996840808,68.21035320950136,341.3481464745794,26.109206288959843,1557.5025829340427,161.66136200693026,46.21450190331935,15.18862591145096,75.86576202874184,154.37861855164763,99.64371778726462,9.970348233851375,794.4166717000722,1326.0088476571766,644.2071038144312,668.7914033713265,12.034332061672254,0.976008409746482,2161.055400272149,119.79571726506076,229.54485361916255,51.79412888470989,1708.130296167735,51.79040433548113,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2363.0471651287003,902.893085551402,393.9897100587936,508.9033754926084,44.48422870173066,1415.6698508755676,640.2407775557151,565.9698134157278,209.45925990412456,5021.47693442935,902.893085551402,393.9897100587936,508.9033754926084,96.87467149846944,4021.709177379479,1292.4899470266332,2207.1205547018462,522.0986756509994,4269.854485253351,1396.5035698221395,4147.854485253352,553.836516284033,1865.3378685430584,1363.50356982214,365.17653060412096,902.8930855514064,71.82104089613459,296.5182974140414,324.22069890255045,210.3330483386799,2037.865039271743,2231.989445981608,64.05473540689927,68.15382103440278,144.3772548092697,266.37825275916083,234.4552705361668,575.6939819415802,928.9131284518544,81.02072018936614,190.56771657980732,195.45141368950704,408.86748363327126,620.0239871574901,516.3450473719114,1455.854683623714,1469.7250440840312,164.64155828961793,1415.6698508755676,565.9698134157278,209.45925990412456,640.2407775557151,708.5920947123694,309.3241932263921,253.3485257328492,117.41544962068669,26.98958758327022,213.84449416582265,248.42716555686715,186.9868240095217,293.7438034704186,3422.2741654988995,170.33284794355296,306.13782536892137,247.43888879499116,184.0334986484435,120.36720016493112,9.095285796181653,24.132496614509943,3932.226004029285,1623.7595175448537,1008.1592537866522,550.1706092521626,750.136623445616,1865.9072392960663,673.7713882885728,601.2613518889406,274.2182513117254,316.65624780682793,2066.318764733218,949.9881292562808,406.8979018977117,275.9523579404373,433.4803756387881,,,,Houses,Housing,Urban,Central,Centre,Lower diff --git a/predihood/config.py b/predihood/config.py index 85566631a7d188f251815f8b35426407955c4230..9b7e88989142acb5be760479c17ca08b518c3e6d 100644 --- a/predihood/config.py +++ b/predihood/config.py @@ -27,6 +27,7 @@ OLD_PREFIX, NEW_PREFIX = "old_", "new_" RANDOM_STATE = 0 # make classifiers deterministic TRAIN_SIZE, TEST_SIZE = 0.8, 0.2 TOPS_K = [10, 20, 30, 40, 50, 75, 100] # define top-k to generate lists of selected indicators +PREFERRED_LANGUAGE = "english" # 4. define EV, the possible values for each one and their translation (because data come from a French company). ENVIRONMENT_VALUES = { @@ -76,6 +77,14 @@ ENVIRONMENT_VALUES = { # names of EV, i.e. ['building_type', 'building_usage', 'landscape', 'morphological_position', 'geographical_position', 'social_class'] ENVIRONMENT_VARIABLES = list(ENVIRONMENT_VALUES.keys()) +ENVIRONMENT_VARIABLES_FR = { + "building_type": "type_de_bâtiments", + "building_usage": "usage_des_bâtiments", + "landscape": "paysage", + "morphological_position": "position_morphologique", + "geographical_position": "position_géographique", + "social_class": "classe_sociale" +} # translation of each value from French to English, ie. without the level with EV' names TRANSLATION = {} diff --git a/predihood/main.py b/predihood/main.py index 5d7135ad39559fe3088eb181064dcef48025af67..b868c690972ccb2dc72cda2bf50e969edd4aec5f 100644 --- a/predihood/main.py +++ b/predihood/main.py @@ -8,12 +8,12 @@ import json import logging import os import webbrowser +import predihood.config from flask import Flask, flash, render_template, request, send_from_directory from predihood import model from predihood.classes.Data import Data from predihood.classifiers_list import AVAILABLE_CLASSIFIERS -from predihood.config import TOPS_K, ENVIRONMENT_VALUES from predihood.predict import compute_all_accuracies, predict_one_iris from predihood.utility_functions import signature, get_classifier, set_classifier, add_assessment_to_file from sklearn.utils._testing import ignore_warnings @@ -25,7 +25,7 @@ app.config["JSON_SORT_KEYS"] = False url = "http://127.0.0.1:8081/" -@app.route('/', defaults={'page': None}) +@app.route('/', defaults={'page': None}, methods=["GET"]) def index(page): """ Render the main page of the interface, i.e. `cartographic-interface.html`. @@ -35,7 +35,12 @@ def index(page): """ if not model.db.connection_status: # if no connection, display a flashing message flash("Could not connect to the MongoDB database ! Check the connection.", "danger") - return render_template('index.html') # 'cartographic-interface.html' + if "lang" in request.args: + predihood.config.PREFERRED_LANGUAGE = request.args["lang"] + else: + predihood.config.PREFERRED_LANGUAGE = "english" + print(predihood.config.PREFERRED_LANGUAGE) + return render_template("index.html", language=predihood.config.PREFERRED_LANGUAGE) @app.route('/cartographic-interface.html', methods=["GET"]) @@ -46,7 +51,7 @@ def get_cartographic_page(): Returns: The page to display. """ - return render_template('cartographic-interface.html') + return render_template('cartographic-interface.html', language=predihood.config.PREFERRED_LANGUAGE) @app.route('/algorithmic-interface.html', methods=["GET"]) @@ -57,7 +62,7 @@ def get_algorithms_page(): Returns: The page to display. """ - return render_template('algorithmic-interface.html') + return render_template('algorithmic-interface.html', language=predihood.config.PREFERRED_LANGUAGE) @app.route('/details-iris.html', methods=["GET"]) @@ -73,7 +78,7 @@ def get_details_iris(): dict_code_label = model.parse_json_to_dict(model.json_iris_indicator_code_to_label) if iris is None: flash("No corresponding iris for code " + code_iris + ".", "warning") - return render_template('details-iris.html', iris=iris, dict_code_label=dict_code_label) + return render_template('details-iris.html', iris=iris, dict_code_label=dict_code_label, language=predihood.config.PREFERRED_LANGUAGE) @app.route('/getClassifiers', methods=["GET"]) @@ -123,13 +128,12 @@ def run_algorithm(): # 2. create an instance of the given classifier and tune it with user's parameters clf = get_classifier(clf_name) clf = set_classifier(clf, parameters) - log.info(clf) # 3. run experiment on data to get accuracies for each EV and each list of selected indicators data = Data(normalization="density", filtering=True) data.init_all_in_one() accuracies = compute_all_accuracies(data, clf, train_size, test_size, remove_outliers, remove_rural) - return {"results": accuracies, "tops_k": TOPS_K} + return {"results": accuracies, "tops_k": predihood.config.TOPS_K} @app.route('/predict_iris', methods=["GET"]) @@ -214,20 +218,33 @@ def get_iris_from_name(): query = request.args['querySearch'] iris = model.get_iris_from_name(query) if iris is None or len(iris) == 0: - flash("No corresponding iris for query " + query + ".", "warning") + if predihood.config.PREFERRED_LANGUAGE == "french": + flash("Pas d'IRIS pour la requête " + query + ".", "warning") + else: + flash("No corresponding iris for query " + query + ".", "warning") else: - flash(str(len(iris)) + " iris found for query " + query + ".", "success") + if predihood.config.PREFERRED_LANGUAGE == "french": + flash(str(len(iris)) + " iris trouvés pour la requête " + query + ".", "success") + else: + flash(str(len(iris)) + " iris found for query " + query + ".", "success") return json.dumps({'status': 'OK', 'geojson': iris}) @app.route('/getEnvironmentValues', methods=["GET"]) def get_environment_values(): variables_with_values = {} - for env in ENVIRONMENT_VALUES: - temp = [] - for key in ENVIRONMENT_VALUES[env]: - temp.append(ENVIRONMENT_VALUES[env][key]) # get english values - variables_with_values[env] = temp + if predihood.config.PREFERRED_LANGUAGE == "french": + for env in predihood.config.ENVIRONMENT_VALUES: + temp = [] + for key in predihood.config.ENVIRONMENT_VALUES[env]: + temp.append(key) # get french values + variables_with_values[env] = temp + else: + for env in predihood.config.ENVIRONMENT_VALUES: + temp = [] + for key in predihood.config.ENVIRONMENT_VALUES[env]: + temp.append(predihood.config.ENVIRONMENT_VALUES[env][key]) # get english values + variables_with_values[env] = temp return json.dumps(variables_with_values) # {"result": variables_with_values} @@ -241,12 +258,17 @@ def add_iris_to_csv(): A message that explain the status of the request, i.e. OK if the IRIS has been added, KO else. """ assessed_values = [] - for env in ENVIRONMENT_VALUES: + for env in predihood.config.ENVIRONMENT_VALUES: assessed_values.append(request.args[env]) message = add_assessment_to_file(request.args['code_iris'], assessed_values) return json.dumps({"status": message}) +@app.route("/get_preferred_language", methods=["GET"]) +def get_preferred_language(): + return json.dumps({"preferred_language": predihood.config.PREFERRED_LANGUAGE}) + + @app.route('/favicon.ico') @app.route('/<page>/favicon.ico') def favicon(): diff --git a/predihood/predict.py b/predihood/predict.py index d67729b294456e7015e0ba98a39d099489472f85..e3a277066896e54f0ef9d789be478a8f87da0603 100644 --- a/predihood/predict.py +++ b/predihood/predict.py @@ -1,12 +1,13 @@ import logging -from collections import OrderedDict +import predihood.config +from collections import OrderedDict from predihood.classes.Data import Data from predihood.classes.Dataset import Dataset from predihood.classes.MethodPrediction import MethodPrediction -from predihood.config import ENVIRONMENT_VARIABLES, TRAIN_SIZE, TEST_SIZE +from predihood.config import ENVIRONMENT_VARIABLES, TRAIN_SIZE, TEST_SIZE, ENVIRONMENT_VALUES, ENVIRONMENT_VARIABLES_FR from predihood.selection import retrieve_lists -from predihood.utility_functions import check_dataset_size, get_most_frequent +from predihood.utility_functions import check_train_test_percentages, get_most_frequent from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier from sklearn.exceptions import ConvergenceWarning from sklearn.linear_model import LogisticRegression, SGDClassifier @@ -46,7 +47,7 @@ def compute_all_accuracies(data, clf, train_size, test_size, remove_outliers=Fal a dictionary of results for each EV and each list of selected indicators """ log.info("... Computing accuracies ...") - train_size, test_size = check_dataset_size(train_size, test_size) + train_size, test_size = check_train_test_percentages(train_size, test_size) data_not_filtered = Data(normalization="density", filtering=False) data_not_filtered.init_all_in_one() @@ -54,7 +55,10 @@ def compute_all_accuracies(data, clf, train_size, test_size, remove_outliers=Fal lists = retrieve_lists() results = {} for j, env in enumerate(ENVIRONMENT_VARIABLES): - results[env] = OrderedDict() + if predihood.config.PREFERRED_LANGUAGE == "french": + results[ENVIRONMENT_VARIABLES_FR[env]] = OrderedDict() + else: + results[env] = OrderedDict() log.debug("--- %s ---", env) dataset = Dataset(data_not_filtered, env, selected_indicators=data_not_filtered.indicators, train_size=train_size, test_size=test_size, outliers=remove_outliers, _type='supervised') @@ -65,8 +69,12 @@ def compute_all_accuracies(data, clf, train_size, test_size, remove_outliers=Fal algo = MethodPrediction(name="", dataset=dataset, classifier=clf) algo.fit() algo.compute_performance() - results[env]["accuracy_none"] = algo.accuracy - results[env]["accuracies"] = OrderedDict() + if predihood.config.PREFERRED_LANGUAGE == "french": + results[ENVIRONMENT_VARIABLES_FR[env]]["accuracy_none"] = algo.accuracy + results[ENVIRONMENT_VARIABLES_FR[env]]["accuracies"] = OrderedDict() + else: + results[env]["accuracy_none"] = algo.accuracy + results[env]["accuracies"] = OrderedDict() log.info("accuracy for %s without filtering: %f", env, algo.accuracy) for top_k, lst in lists.items(): @@ -77,11 +85,16 @@ def compute_all_accuracies(data, clf, train_size, test_size, remove_outliers=Fal algo2.fit() algo2.compute_performance() mean_classifier += algo2.accuracy - results[env]["accuracies"][str(top_k)] = algo2.accuracy + if predihood.config.PREFERRED_LANGUAGE == "french": + results[ENVIRONMENT_VARIABLES_FR[env]]["accuracies"][str(top_k)] = algo2.accuracy + else: + results[env]["accuracies"][str(top_k)] = algo2.accuracy log.info("accuracy for %s with %s: %f", env, top_k, algo2.accuracy) - print("means:", results[env]) mean_classifier /= len(CLASSIFIERS) - results[env]["mean"] = mean_classifier + if predihood.config.PREFERRED_LANGUAGE == "french": + results[ENVIRONMENT_VARIABLES_FR[env]]["mean"] = mean_classifier + else: + results[env]["mean"] = mean_classifier log.info("mean for classifier: %f", mean_classifier) results = OrderedDict(results) log.info(results) @@ -103,7 +116,7 @@ def predict_one_iris(iris_code, data, clf, train_size, test_size, remove_outlier Returns: A dictionary containing predictions for each EV. """ - train_size, test_size = check_dataset_size(train_size, test_size) + train_size, test_size = check_train_test_percentages(train_size, test_size) lists = retrieve_lists() predictions = {} @@ -116,8 +129,17 @@ def predict_one_iris(iris_code, data, clf, train_size, test_size, remove_outlier algorithm = MethodPrediction(name='', dataset=dataset, classifier=clf) algorithm.fit() algorithm.predict(iris_code) - predictions_lst.append(algorithm.prediction) - predictions[env] = get_most_frequent(predictions_lst) # get the most frequent value and the number of occurrences + print(predihood.config.PREFERRED_LANGUAGE) + if predihood.config.PREFERRED_LANGUAGE == "french": + predicted_value = list(ENVIRONMENT_VALUES[env].keys())[list(ENVIRONMENT_VALUES[env].values()).index(algorithm.prediction)] # get french translation of the predicted value + else: + predicted_value = algorithm.prediction + predictions_lst.append(predicted_value) + print(predictions_lst) + if predihood.config.PREFERRED_LANGUAGE == "french": + predictions[ENVIRONMENT_VARIABLES_FR[env]] = get_most_frequent(predictions_lst) + else: + predictions[env] = get_most_frequent(predictions_lst) # get the most frequent value and the number of occurrences print(predictions) # TODO: give an example of the dictionary return predictions diff --git a/predihood/static/js/algorithms.js b/predihood/static/js/algorithms.js index 3a781945a2ec9136033f1979fce65995479de05f..267e946941fec7413c2e90c98f0d68dd73340909 100644 --- a/predihood/static/js/algorithms.js +++ b/predihood/static/js/algorithms.js @@ -6,7 +6,7 @@ let trainPercentage = $("#trainPercentage").val(); // to update test percentage let testPercentage = $("#testPercentage").val(); // to update train percentage depending on test percentage let request_run = null; // the request send to the server (with classifier and its parameters) const MAX_PARAMETERS = 5; - +let preferred_language_algo = get_preferred_language(); // get parameters of the selected classifier and display them in the interface. $("#selectAlgorithm").change(function () { let algorithm_name = $(this).children("option:selected").val(); @@ -112,15 +112,23 @@ $("#runBtn") // header of table: None, 10, 20, ..., 100, Mean let header = $("<tr>") header.append("<th></th>"); - header.append("<th title='Accuracy obtained with all indicators'>None</th>") - for (let key of result["tops_k"]) { header.append("<th title='Accuracy obtained by list with "+key+" indicators'>" + key + "</th>") } // adding header with tops-k - header.append("<th title='Mean accuracy for the environment variable'>Mean</th>") + if(preferred_language_algo === "french") { + header.append("<th title='Précision obtenue avec tous les indicateurs'><i>I</i></th>") + for (let key of result["tops_k"]) { header.append("<th title='Précision obtenue avec la liste de "+key+" indicateurs'>" + key + "</th>") } // adding header with tops-k + header.append("<th title=\"Précision moyenne obtenue pour la variable d'environnement\">Moyenne</th>") + } else { + header.append("<th title='Accuracy obtained with all indicators'>I</th>") + for (let key of result["tops_k"]) { header.append("<th title='Accuracy obtained by list with "+key+" indicators'>" + key + "</th>") } // adding header with tops-k + header.append("<th title='Mean accuracy for the environment variable'>Mean</th>") + } table.append(header); - + console.log(results) // content of table with computed accuracies for (let key in results) { // iterating over env variables let row = $("<tr>"); - let env = results[key]; + console.log(key) + console.log(typeof(results[key])) + let env = capitalizeFirstLetter(results[key].split("_").join(" ")); let max = getMaxValueDict(env["accuracies"], env["accuracy_none"]); row.append("<td>" + key + "</td>") @@ -142,7 +150,12 @@ $("#runBtn") } // download icon - let download = $("<i class='fas fa-download' style='margin-left: 1rem;' title='Export this table to Excel file.'></i>") + let download; + if(preferred_language_algo === "french") { + download = $("<i class='fas fa-download' style='margin-left: 1rem;' title='Exporter cette table comme un fichier Excel.'></i>") + } else { + download = $("<i class='fas fa-download' style='margin-left: 1rem;' title='Export this table as an Excel file.'></i>") + } download.on("click", function (e) { e.preventDefault(); console.log($(this)) @@ -175,7 +188,12 @@ $("#runBtn") mean_clf += results[env]["mean"]; } mean_clf /= Object.keys(results).length; - containing_table.append("<br/> <b>Mean for this classifier: </b>" + mean_clf.toFixed(2) + "%"); + if(preferred_language_algo === "french") { + containing_table.append("<br/> <b>Moyenne de cet algorithme : </b>" + mean_clf.toFixed(2) + "%"); + } else { + containing_table.append("<br/> <b>Mean for this classifier: </b>" + mean_clf.toFixed(2) + "%"); + } + // append all to HTML $("#resultsDiv").append(containing_table); @@ -297,28 +315,31 @@ function addParameters(jsonData) { * Adds a "show more" or "show less" link in the classifier's parameters section. */ function addShowMoreLess() { - $("#specificParameters") - .append($("<a>") - .text("Show more...") - .attr("id", "showMoreLessParams") - .attr("class", "seeMore") - .attr("title", "Show more parameters") - .attr("href", "#") - ); + let link_show_more = $("<a>").attr("id", "showMoreLessParams").attr("class", "seeMore").attr("href", "#") + if(preferred_language_algo === "french") { + link_show_more.text("Afficher plus...").attr("title", "Afficher plus de paramètres") + } else { + link_show_more.text("Show more...").attr("title", "Show more parameters") + } + $("#specificParameters").append(link_show_more); $('#showMoreLessParams').click(function () { $(this).toggleClass('seeMore'); if ($(this).hasClass('seeMore')) { - $(this) - .text('Show more') - .attr("title", "Show more parameters"); + if(preferred_language_algo === "french") { + $(this).text('Afficher plus').attr("title", "Afficher plus de paramètres"); + } else { + $(this).text('Show more').attr("title", "Show more parameters"); + } $("#specificParameters li.hiddenParam").each(function () { $(this).hide(); // hide other parameters }); } else { - $(this) - .text('Show less') - .attr("title", "Show less parameters"); + if(preferred_language_algo === "french") { + $(this).text('Afficher moins').attr("title", "Afficher moins de paramètres"); + } else { + $(this).text('Show less').attr("title", "Show less parameters"); + } $("#specificParameters li.hiddenParam").each(function () { $(this).show(); // show all parameters }); diff --git a/predihood/static/js/carto.js b/predihood/static/js/carto.js index 274f143b1528a1ea5966a65eab0cc755160b415c..281def39e09d18fe1902eec2973d871b74239d27 100644 --- a/predihood/static/js/carto.js +++ b/predihood/static/js/carto.js @@ -16,7 +16,7 @@ let osmLayer = null; // openstreetmap basic layer let irisLayer = null; // layer of displayed IRIS let previously_selected_algorithm = null; let environment_variables = getEnvironmentVariables(); // get the json corresponding to the list of environment variables with the possible values -console.log(environment_variables) +let preferred_language_carto = get_preferred_language(); // get the language chosen in index.html /** * Initialize the map @@ -76,7 +76,10 @@ function resetHighlightAll() { } } - +/** + * Display popup with several information about the neighbourhood (descriptive information and environment variables) when clicking on it. + * @param e the event corresponding to the click. + */ function displayPopup(e) { var layer = e.target; var code_iris = layer.feature.properties.CODE_IRIS @@ -85,6 +88,19 @@ function displayPopup(e) { // common part of the popup let divInformation = $("<div>"); + if(preferred_language_carto === "french") { + divInformation + .append("CODE IRIS : " + layer.feature.properties.CODE_IRIS).append($("<br>")) + .append("IRIS : " + layer.feature.properties.NOM_IRIS).append($("<br>")) + .append("COMMUNE : " + layer.feature.properties.NOM_COM).append($("<br>")) + let moreInfosLink = $("<a>"); + moreInfosLink + .prop("href", "details-iris.html?code_iris="+layer.feature.properties.CODE_IRIS) + .prop("target", "_blank") + .text("Plus de détails") + .append($("<br>")); + divInformation.append(moreInfosLink); + } else { divInformation .append("IRIS CODE: " + layer.feature.properties.CODE_IRIS).append($("<br>")) .append("IRIS: " + layer.feature.properties.NOM_IRIS).append($("<br>")) @@ -96,6 +112,8 @@ function displayPopup(e) { .text("More details") .append($("<br>")); divInformation.append(moreInfosLink); + } + if($("#assessmentMode").is(":checked")) { // alert("assessment mode"); @@ -109,9 +127,12 @@ function displayPopup(e) { divInformation.append(div_container) } - let to_csv_button = $("<button>") - .text("Add to dataset") - .prop("id", "addAssessmentButton"); + let to_csv_button = $("<button>").prop("id", "addAssessmentButton"); + if(preferred_language_carto === "french") { + to_csv_button.text("Ajouter au jeu de données"); + } else { + to_csv_button.text("Add to dataset"); + } let messageTooltip = divInformation[0].outerHTML + to_csv_button[0].outerHTML; layer.bindPopup(messageTooltip) @@ -200,22 +221,22 @@ function addLayerFromGeoJSON(geojson, events, style, typeMethod){ */ function eventsIRIS(feature, layer) { layer.on({ - //mouseover: highlightFeature, + mouseover: highlightFeature, //mouseout: resetHighlight, - //click: clickProperties click: displayPopup //showPredictions }); } +/** + * Allow the validation of input fields using "enter key". + * @param event the event gathered (enter key pressed) + */ function eventValidateButton(event) { // a generic method to allow the validation of input fields using "enter key" if(event.keyCode == 13) // enter key has been pressed and released, back to parent and click on the <button> event.target.parentNode.querySelector("button").click(); } -function capitalizeFirstLetter(string) { - return string.charAt(0).toUpperCase() + string.slice(1); -} // updating values of printed parameters $("#inputZoomLevel").val(DEFAULT_ZOOM_LEVEL_MIN_FOR_DISPLAY); diff --git a/predihood/static/js/prediction.js b/predihood/static/js/prediction.js index 0b1aaf8af6b7a72b7556402584f938df45fb6456..42e3c5745e871b48f331943aa91c3378768eb6b3 100644 --- a/predihood/static/js/prediction.js +++ b/predihood/static/js/prediction.js @@ -1,5 +1,6 @@ function predict(iris_code, algorithm_name) { - let predictions = null + $("body").css("cursor", "progress"); + let predictions = null; $.ajax({ type: "GET", url: "/predict_iris", @@ -12,10 +13,12 @@ function predict(iris_code, algorithm_name) { success: function(result) { console.log(result) console.log(result['predictions']) - predictions = result['predictions'] + predictions = result['predictions']; + $("body").css("cursor", "default"); }, error: function(result, textStatus, errorThrown) { console.log(errorThrown); + $("body").css("cursor", "default"); } }); return predictions diff --git a/predihood/static/js/utils.js b/predihood/static/js/utils.js index 139ddb85bf86df01d3642f6adf550cb9bb0b5425..6df8aa1c088df224555cb6c92f5a6fc7862ab8dc 100644 --- a/predihood/static/js/utils.js +++ b/predihood/static/js/utils.js @@ -188,4 +188,42 @@ function getEnvironmentVariables() { } }); return env_var; +} + + +function highlightFeature(e) { + var layer = e.target; + layer.setStyle({ + weight: 1, + color: '#666', + fillOpacity: 0.25 + }); + +} + +function get_preferred_language() { + let chosen_language = undefined; + + $.ajax({ + type: "GET", + url: "/get_preferred_language", + async: false, + contentType: 'application/json;charset=UTF-8', + success: function(result) { + chosen_language = JSON.parse(result)["preferred_language"] + }, + error: function(result, textStatus, errorThrown) { + console.log(errorThrown) + } + }) + return chosen_language +} + +/** + * Capitalize first letter of a string. + * @param string the string on which the first letter will be capitalized + * @returns {string} the string with the first letter capitalized + */ +function capitalizeFirstLetter(string) { + return string.charAt(0).toUpperCase() + string.slice(1); } \ No newline at end of file diff --git a/predihood/templates/algorithmic-interface.html b/predihood/templates/algorithmic-interface.html index a692689dd77e58aa5e3e066c236869f1e766bad9..381eceee3517664d5029aa3eab0e8af694deae19 100644 --- a/predihood/templates/algorithmic-interface.html +++ b/predihood/templates/algorithmic-interface.html @@ -5,67 +5,109 @@ <div class="row"> <aside id="sidebar" class="col-3 min-vh-100 max-vh-100" style="position: relative;"> {% include 'header.html' %} - - <p class="text-gray font-weight-bold text-uppercase px-3 small pb-4 mb-0" - title="Choose a classifier among the list below.">Select a classifier</p> + {% if language == "french" %} + <p class="text-gray font-weight-bold text-uppercase px-3 small pb-4 mb-0" title="Choisir un algorithm parmi la liste ci-dessous.">Choisir un algorithme</p> + {% else %} + <p class="text-gray font-weight-bold text-uppercase px-3 small pb-4 mb-0" title="Choose an algorithm among the list below.">Select an algorithm</p> + {% endif %} <form id="formAlgorithm" class="px-3 small pb-4 mb-0"> <select id="selectAlgorithm"> - <option selected value="Algorithm"> -- select an algorithm --</option> + {% if language == "french" %} + <option selected value="Algorithme"> -- choisir un algorithme --</option> + {% else %} + <option selected value="Algorithm"> -- select an algorithm --</option> + {% endif %} </select> </form> <div id="tuningSection" style="visibility: hidden"> <hr/> - <p class="font-weight-bold text-uppercase px-3 small pb-4 mb-0" title="Tune the selected classifier."> - Tune parameters</p> + {% if language == "french" %} + <p class="font-weight-bold text-uppercase px-3 small pb-4 mb-0" title="Paramétrer l'algorithme choisi.">Paramétrer l'algorithme</p> + {% else %} + <p class="font-weight-bold text-uppercase px-3 small pb-4 mb-0" title="Tune the selected algorithm.">Tune algorithm</p> + {% endif %} <form id="formParameters"> <div class="col-12" id="divParameters"> - <h6>Classifier's parameters<i id="specificParametersTitle" class="fas fa-angle-double-up"></i> - </h6> - <ul id="specificParameters" class="nav flex-column bg-white mb-0" style="display: block"></ul> - <h6>Common parameters<i id="commonParametersTitle" class="fas fa-angle-double-up"></i></h6> - <ul id="commonParameters" class="nav flex-column bg-white mb-0" style="display: block"></ul> + {% if language == "french" %} + <h6>Paramètres spécifiques<i id="specificParametersTitle" class="fas fa-angle-double-up"></i></h6> + <ul id="specificParameters" class="nav flex-column bg-white mb-0" style="display: block"></ul> + <h6>Paramèteres communs<i id="commonParametersTitle" class="fas fa-angle-double-up"></i></h6> + <ul id="commonParameters" class="nav flex-column bg-white mb-0" style="display: block"></ul> + {% else %} + <h6>Specific parameters<i id="specificParametersTitle" class="fas fa-angle-double-up"></i></h6> + <ul id="specificParameters" class="nav flex-column bg-white mb-0" style="display: block"></ul> + <h6>Common parameters<i id="commonParametersTitle" class="fas fa-angle-double-up"></i></h6> + <ul id="commonParameters" class="nav flex-column bg-white mb-0" style="display: block"></ul> + {% endif %} </div> </form> - <p class="font-weight-bold text-uppercase px-3 small pb-4 mb-0" - title="Tune the repartition of the data into train and test sets." style="padding-top: 1rem; padding-bottom: 0; margin-bottom: 0">Tune dataset</p> + {% if language == "french" %} + <p class="font-weight-bold text-uppercase px-3 small pb-4 mb-0" title="Paramétrer la répartition entre les jeux d'apprentissage et de test." style="padding-top: 1rem; padding-bottom: 0; margin-bottom: 0">Jeux de données</p> + {% else %} + <p class="font-weight-bold text-uppercase px-3 small pb-4 mb-0" title="Tune the repartition of the data into train and test sets." style="padding-top: 1rem; padding-bottom: 0; margin-bottom: 0">Tune dataset</p> + {% endif %} <ul class="nav flex-column bg-white mb-0"> <li class="nav-item"> <div class="nav-link"> - <i class="fa fa-question-circle mr-3 text-primary fa-fw" - title="Size for the train set. The value is in percentage and between 1 and 99%."></i> - Train size - <input id="trainPercentage" type="number" min="1" max="99" step="1" value="80" - title="The percentage of the dataset used to train the classifier."> + {% if language == "french" %} + <i class="fa fa-question-circle mr-3 text-primary fa-fw" title="Taille des données d'entraînement. La valeur est un pourcentage entre 1 et 99%."></i> + Données d'entraînement + <input id="trainPercentage" type="number" min="1" max="99" step="1" value="80" title="Le pourcentage des données utilisées pour l'apprentissage."> + {% else %} + <i class="fa fa-question-circle mr-3 text-primary fa-fw" title="Size for the train set. The value is a percentage and should be between 1 and 99%."></i> + Train size + <input id="trainPercentage" type="number" min="1" max="99" step="1" value="80" title="The percentage of the dataset used to train the algorithm."> + {% endif %} + </div> </li> <li class="nav-item"> <div class="nav-link"> - <i class="fa fa-question-circle mr-3 text-primary fa-fw" - title="Size for the test set. The value is in percentage and between 1 and 99%."></i> - Test size - <input id="testPercentage" type="number" min="1" max="99" step="1" value="20" - title="The percentage of the dataset used to test the classifier."> + {% if language == "french" %} + <i class="fa fa-question-circle mr-3 text-primary fa-fw" title="Taille des données de test. La valeur est un pourentage entre 1 et 99%."></i> + Données de test + <input id="testPercentage" type="number" min="1" max="99" step="1" value="20" title="Le pourcentage des données utilisées pour le test."> + {% else %} + <i class="fa fa-question-circle mr-3 text-primary fa-fw" title="Size for the test set. The value is a percentage and should be between 1 and 99%."></i> + Test size + <input id="testPercentage" type="number" min="1" max="99" step="1" value="20" title="The percentage of the dataset used to test the algorithm."> + {% endif %} </div> </li> <li class="nav-item"> <div class="nav-link"> - <i class="fa fa-question-circle mr-3 text-primary fa-fw" title="True to remove outliers in the dataset, False else."></i> - Remove outliers - <input id="removeOutliers" type="checkbox" title="True to remove outliers, False else."> - <br> - <i class="fa fa-question-circle mr-3 text-primary fa-fw" title="True to remove rural neighbourhoods in the dataset, False else."></i> - Remove rural - <input id="removeRural" type="checkbox" title="True to remove rural neighbourhoods, False else."> + {% if language == "french" %} + <i class="fa fa-question-circle mr-3 text-primary fa-fw" title="Cocher pour retirer les IRIS détectés comme abberants du jeu de données."></i> + Retirer les IRIS abberants + <input id="removeOutliers" type="checkbox" title="Cocher pour retirer les IRIS abbertants."> + <br> + <i class="fa fa-question-circle mr-3 text-primary fa-fw" title="Cocher pour retirer les IRIS ruraux du jeu de données."></i> + Retirer les IRIS ruraux + <input id="removeRural" type="checkbox" title="Cocher pour retirer els IRIS ruraux."> + {% else %} + <i class="fa fa-question-circle mr-3 text-primary fa-fw" title="Check it to remove outliers in the dataset."></i> + Remove outliers + <input id="removeOutliers" type="checkbox" title="Check it to remove outliers."> + <br> + <i class="fa fa-question-circle mr-3 text-primary fa-fw" title="Check it to remove rural neighbourhoods in the dataset."></i> + Remove rural + <input id="removeRural" type="checkbox" title="Check it to remove rural neighbourhoods."> + {% endif %} </div> </li> </ul> - <button id="runBtn" class="btn btn-success" - title="Train and test the tuned classifier on data. Results appear in the next section (at the centre)."> - Train, test and evaluate - </button> + {% if language == "french" %} + <button id="runBtn" class="btn btn-success" title="Entraîner et tester l'algorithme paramétré sur les données."> + Entraîner, tester et évaluer + </button> + {% else %} + <button id="runBtn" class="btn btn-success" title="Train and test the tuned algorithm on data."> + Train, test and evaluate + </button> + {% endif %} <!--<button id="abortRun" class="btn btn-danger" title="Arbort the current request">Abort</button>--> </div> {% include 'footer.html' %} @@ -73,13 +115,19 @@ <main class="col-9" id="resultsDiv"> <!-- <button id="sidebarCollapse" type="button" class="btn btn-light bg-white rounded-pill shadow-sm px-4 mb-4"><i class="fa fa-bars mr-2"></i><small class="text-uppercase font-weight-bold"></small></button> --> - <h2 title="Results of the tuned classifier">Results<i class="far fa-trash-alt" id="clearResults" - title="Clear all results" + {% if language == "french" %} + <h2 title="Résultats de l'algorihtme paramétré">Resultats<i class="far fa-trash-alt" id="clearResults" + title="Supprimer tous les résultats" style="color: red; font-size: 22px; padding-left: 0.5rem"></i> + {% else %} + <h2 title="Results of the tuned algorithm">Results<i class="far fa-trash-alt" id="clearResults" + title="Clear all results" + style="color: red; font-size: 22px; padding-left: 0.5rem"></i> + {% endif %} </h2> </main> </div> <script src="{{ url_for('static', filename='js/algorithms.js') }}"></script> <script src="{{ url_for('static', filename='js/utils.js') }}"></script> -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/predihood/templates/base.html b/predihood/templates/base.html index be2733f5046866b0a67880643b28521d11ca2964..4ca531b7bfab88e019ee1cad9968e12c648b42c0 100644 --- a/predihood/templates/base.html +++ b/predihood/templates/base.html @@ -11,6 +11,7 @@ <script src="{{url_for('static', filename='lib/jquery-3.3.1.js')}}"></script> <link href="{{url_for('static', filename='lib/fontawesome-free-5.13.0-web/css/all.css')}}" rel="stylesheet" media="all" type="text/css"> <script src="{{url_for('static', filename='lib/table2excel.js')}}"></script> + <script src="{{ url_for('static', filename='js/utils.js') }}"></script> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> @@ -20,5 +21,4 @@ <!--<script src="{{url_for('static', filename='lib/rainbowvis.js')}}"></script> --> <script type="text/javascript" src="{{url_for('static', filename='lib/bootstrap-4.0.0-dist/js/bootstrap.min.js')}}"></script> - </html> \ No newline at end of file diff --git a/predihood/templates/cartographic-interface.html b/predihood/templates/cartographic-interface.html index a48a2d57fc05dd1e602cd8c6f4b759c4bb152a3d..c958d19316ec308348f40e2dac3fd6047d88aa9f 100644 --- a/predihood/templates/cartographic-interface.html +++ b/predihood/templates/cartographic-interface.html @@ -26,7 +26,6 @@ <script type="text/javascript" src="{{url_for('static', filename='lib/leaflet/leaflet.js')}}"></script> <!--<script type="text/javascript" src="{{url_for('static', filename='lib/leaflet.ajax.min.js')}}"></script>--> <!--<script type=″text/javascript″ src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>--> -<script src="{{url_for('static', filename='js/utils.js')}}"></script> <script src="{{url_for('static', filename='js/carto.js')}}"></script> <script src="{{url_for('static', filename='js/prediction.js')}}"></script> <script src="{{url_for('static', filename='js/algorithms.js')}}"></script> diff --git a/predihood/templates/footer.html b/predihood/templates/footer.html index d320f7a164a5123588de6dff45571720871c2375..78d0124f734989996f8ade5fec6ae6693dfc4195 100644 --- a/predihood/templates/footer.html +++ b/predihood/templates/footer.html @@ -8,7 +8,11 @@ </div> <hr> <div style="display: flex; justify-content: space-around;"> - <span>Data sources<br>(statistics, IRIS)</span> + {% if language == "french" %} + <span>Sources de données<br>(statistiques, IRIS)</span> + {% else %} + <span>Data sources<br>(statistics, IRIS)</span> + {% endif %} <a href="http://www.insee.fr/"><img src="{{url_for('static', filename='img/insee.jpg')}}" width="43px" height="50px" alt="INSEE"/></a> </div> </footer> \ No newline at end of file diff --git a/predihood/templates/footer2.html b/predihood/templates/footer2.html index f9cfca681dee4f04f9f4fdcc560331a1fca7f3a7..757eddf186208eeb0ced7aeed58faba8e53afda4 100644 --- a/predihood/templates/footer2.html +++ b/predihood/templates/footer2.html @@ -10,7 +10,11 @@ in footer2 (from details-iris), this padding-right creates an horizontal scrolle </div> <hr> <div style="display: flex; justify-content: space-around;"> - <span>Data sources (statistics, IRIS)</span> + {% if language == "french" %} + <span>Sources de données (statistiques, IRIS)</span> + {% else %} + <span>Data sources (statistics, IRIS)</span> + {% endif %} <a href="http://www.insee.fr/"><img src="{{url_for('static', filename='img/insee.jpg')}}" width="43px" height="50px" alt="INSEE"/></a> </div> </footer> \ No newline at end of file diff --git a/predihood/templates/form.html b/predihood/templates/form.html index 8f7581f67ff2dbb568ba8f808271c50c0204d02a..2538de17910a191a26661198c2fd54d7e8bcb306 100644 --- a/predihood/templates/form.html +++ b/predihood/templates/form.html @@ -1,32 +1,50 @@ <div style="text-align: justify;"> -<label for="inputZoomLevel">Minimal zoom level to display IRIS automatically</label> +{% if language == "french" %} + <label for="inputZoomLevel">Niveau de zoom minimal pour afficher les IRIS automatiquement</label> +{% else %} + <label for="inputZoomLevel">Minimal zoom level to display IRIS automatically</label> +{% endif %} <div class="input-group mb-4"> <div class="input-group-prepend"> <button class="btn" type="button" id="boutonEnableDisableZoom"> - <img src="{{url_for('static', filename='css/open-iconic-master/svg/lock-locked.svg')}}" width="16" height="16" alt="Enable/Disable" /> + {% if language == "french" %} + <img src="{{url_for('static', filename='css/open-iconic-master/svg/lock-locked.svg')}}" width="16" height="16" alt="Activer/Désactiver" /> + {% else %} + <img src="{{url_for('static', filename='css/open-iconic-master/svg/lock-locked.svg')}}" width="16" height="16" alt="Enable/Disable" /> + {% endif %} </button> <input type="number" min="12" max="18" value="16" disabled maxlength="1" id="inputZoomLevel" style="width: 3em;" /> <span valign="bottom" class="ml-2 pt-1"> - (actual zoom level = <span id="spanZoomLevel" style="font-weight: bold;">6</span>) + {% if language == "french" %} + (niveau de zoom actuel = <span id="spanZoomLevel" style="font-weight: bold;">6</span>) + {% else %} + (actual zoom level = <span id="spanZoomLevel" style="font-weight: bold;">6</span>) + {% endif %} </span> </div> </div> - -<label for="boutonRechercherCode">Search by IRIS code</label> +{% if language == "french" %} + <label for="boutonRechercherCode">Rechercher par code IRIS</label> +{% else %} + <label for="boutonRechercherCode">Search by IRIS code</label> +{% endif %} <div class="input-group mb-4"> <input type="text" class="form-control" placeholder="740560104" aria-label="740560104" id="inputCode"/> <div class="input-group-append"> <button class="btn" type="button" id="boutonRechercherCode"> - <img src="{{url_for('static', filename='css/package/build/svg/search.svg')}}" alt="Searcg" /> + <img src="{{url_for('static', filename='css/package/build/svg/search.svg')}}" alt="Search" /> </button> </div> </div> - -<label for="boutonRechercherNom">Search by IRIS name or city</label><br> +{% if language == "french" %} + <label for="boutonRechercherNom">Rechercher par nom ou par ville</label><br> +{% else %} + <label for="boutonRechercherNom">Search by IRIS name or city</label><br> +{% endif %} <div class="input-group mb-4"> <input type="text" class="form-control" placeholder="Lyon" pattern=".{3,}" aria-label="Lyon" id="inputName"/> <div class="input-group-append"> @@ -38,12 +56,22 @@ </div> <div> - Manual assessment: <input type="checkbox" id="assessmentMode"/> + {% if language == "french" %} + Expertise manuelle: <input type="checkbox" id="assessmentMode"/> + {% else %} + Manual assessment: <input type="checkbox" id="assessmentMode"/> + {% endif %} </div> <div class="input-group mb-3"> - <button class="btn" type="button" id="boutonEffacer">Clear - <img class="align-middle" src="{{url_for('static', filename='css/package/build/svg/trashcan.svg')}}" alt="Clear" /> + <button class="btn" type="button" id="boutonEffacer"> + {% if language == "french" %} + Effacer + <img class="align-middle" src="{{url_for('static', filename='css/package/build/svg/trashcan.svg')}}" alt="Effacer" /> + {% else %} + Clear + <img class="align-middle" src="{{url_for('static', filename='css/package/build/svg/trashcan.svg')}}" alt="Clear" /> + {% endif %} </button> </div> diff --git a/predihood/templates/header.html b/predihood/templates/header.html index d427195bce814585ec0e6e4e92251cd2f7cf806a..bccf4104bcd7444e1ff380cc8a18c914a15abe51 100644 --- a/predihood/templates/header.html +++ b/predihood/templates/header.html @@ -1,5 +1,9 @@ <header class="mb-3"> <h1><a href="/"><img src="{{url_for('static', filename='img/favicon.png')}}"></a> predihood</h1> - <em>A tool for visualizing IRIS</em> + {% if language == "french" %} + <em>Un outil de visualisation des IRIS</em> + {% else %} + <em>A tool for visualizing IRIS</em> + {% endif %} <hr> </header> \ No newline at end of file diff --git a/predihood/templates/index.html b/predihood/templates/index.html index 80387df0e9dbe1411c85e0625f4a7c40e314992b..4724c4b9040a79f9e70f744cd030c2aa7f1ba438 100644 --- a/predihood/templates/index.html +++ b/predihood/templates/index.html @@ -2,7 +2,7 @@ {% block content %} <div class="row"> - <div class="col-11"> + <div class="col-10"> <h3 style="margin-top: 0 !important; margin-bottom: 0 !important"> <a href="/"> <img src="{{ url_for('static', filename='img/favicon.png') }}" height="30vh"> @@ -10,8 +10,14 @@ predihood </h3> </div> - <div class="col-1" align="right"> + + <div class="col-2" align="right"> <input type="button" value="Help" data-toggle="modal" data-target="#modalHelp" class="btn btn-primary"> + {% if language == "french" %} + <button id="changeLanguageButton" type="button" class="btn btn-primary"><a href="/?lang=english" style="color: black">english</a></button> + {% else %} + <button id="changeLanguageButton" type="button" class="btn btn-primary"><a href="/?lang=french" style="color: black">french</a></button> + {% endif %} </div> </div> <div class="row"> @@ -19,16 +25,28 @@ <br><br><br> <div style="text-align: center; background: white; border: black 1px solid; padding: 1rem;"> <img src="{{ url_for('static', filename='img/user.png') }}" alt="For users" style="height: 10vh"><br> - <p>I'm looking for a new living place</p><br> - <button id="btnSearch" class="btn btn-success"><a href="cartographic-interface.html" style="color: black">Search a neighbourhood</a></button> + + {% if language == "french" %} + <p>Je suis à la recherche d'un nouveau lieu de vie</p><br> + <button id="btnSearch" class="btn btn-success"><a href="cartographic-interface.html" style="color: black">Rechercher un quartier</a></button> + {% else %} + <p>I'm looking for a new living place</p><br> + <button id="btnSearch" class="btn btn-success"><a href="cartographic-interface.html" style="color: black">Search a neighbourhood</a></button> + {% endif %} </div> </div> <div class="col-6" id="divTune"> <br><br><br> <div style="text-align: center; background: white; border: black 1px solid; padding: 1rem;"> - <img src="{{ url_for('static', filename='img/science.png') }}" alt="For researchers" style="height: 10vh"><br> - <p>I want to tune my classifier</p><br> - <button id="btnTune" class="btn btn-success"><a href="algorithmic-interface.html" style="color: black">Tune classifiers</a></button> + <img src="{{ url_for('static', filename='img/science.png') }}" alt="For researchers" + style="height: 10vh"><br> + {% if language == "french" %} + <p>Je souhaite paramétrer mes algorithmes</p><br> + <button id="btnTune" class="btn btn-success"><a href="algorithmic-interface.html" style="color: black">Paramétrer mes algorithmes</a></button> + {% else %} + <p>I want to tune my classifier</p><br> + <button id="btnTune" class="btn btn-success"><a href="algorithmic-interface.html" style="color: black">Tune my classifiers</a></button> + {% endif %} </div> </div> </div> @@ -43,19 +61,31 @@ </button> </div> <div class="modal-body"> - <p> - This project, bringing together social science and computer science researchers and the start-up - Home in Love, proposes a website for facilitating real estate searches. There are mainly to - objectives. The first one is to improve spatial recommending procedures by facilitating the - search and the comparison of neighbourhoods in France. The second one is to provide a generic - interface for the tuning of algorithms. The main perspective is to recommend neighbourhoods - based on user profiles, integrate more data sources in an automatic way and justify - recommendations to users. - </p> + {% if language == "french" %} + <p> + Ce projet, réunissant des chercheurs en sciences sociales et en informatique et la start-up Home + in Love, propose un site internet pour faciliter les recherches immobilières. Il y a + principalement deux objectifs. Le premier est d'améliorer les procédures de recommandation + spatiale en facilitant la recherche et la comparaison des quartiers en France. Le second est + de fournir une interface générique pour le paramétrage des algorithmes. La perspective + principale est de recommander des quartiers en fonction des profils d'utilisateurs, + d'intégrer davantage de sources de données de manière automatique et de justifier les + recommandations aux utilisateurs. + </p> + {% else %} + <p> + This project, bringing together social science and computer science researchers and the start-up + Home in Love, proposes a website for facilitating real estate searches. There are mainly two + objectives. The first one is to improve spatial recommending procedures by facilitating the + search and the comparison of neighbourhoods in France. The second one is to provide a generic + interface for the tuning of algorithms. The main perspective is to recommend neighbourhoods + based on user profiles, integrate more data sources in an automatic way and justify + recommendations to users. + </p> + {% endif %} </div> </div> </div> </div> {% endblock %} - diff --git a/predihood/tests/tests_prediction.py b/predihood/tests/tests_prediction.py deleted file mode 100644 index daaff2c271273b7d262ec2d3611fe2a9c65bf050..0000000000000000000000000000000000000000 --- a/predihood/tests/tests_prediction.py +++ /dev/null @@ -1,10 +0,0 @@ -import time -import logging -import progressbar - -progressbar.streams.wrap_stderr() -logging.basicConfig() - -for i in progressbar.progressbar(range(10)): - logging.error('Got %d', i) - time.sleep(0.2) \ No newline at end of file diff --git a/predihood/tests/tests_utility_functions.py b/predihood/tests/tests_utility_functions.py new file mode 100644 index 0000000000000000000000000000000000000000..084ae81d6d39249c6cdfb96edbd4716ef8a7a979 --- /dev/null +++ b/predihood/tests/tests_utility_functions.py @@ -0,0 +1,132 @@ +#!/usr/bin/env python +# encoding: utf-8 +# ============================================================================= +# Unit tests for predihood. +# ============================================================================= + +import unittest +import random +import re + +from sklearn.neighbors import KNeighborsClassifier + +from predihood.utility_functions import check_train_test_percentages, intersection, union, similarity, \ + get_most_frequent, add_assessment_to_file, address_to_code, address_to_city, indicator_full_to_short_label, \ + indicator_short_to_full_label, get_classifier, set_classifier, signature + + +class TestCase(unittest.TestCase): + """ + A class for Predihood unit tests. + """ + + # def test_address_to_code(self): + # address = "46 avenue Victor Hugo Tassin" + # code = address_to_code(address) + # assert code == "692440201" + # + # address = "Westminster, London SW1A 0AA, United Kingdom" + # code = address_to_code(address) + # assert code is None + + def test_address_to_city(self): + address = "46 avenue Victor Hugo Tassin" + city = address_to_city(address) + assert city == "Tassin-la-Demi-Lune" + + def test_indicator_full_to_short_label(self): + full_label = "Pop 11-17 ans en 2014 (princ)" + short_label = indicator_full_to_short_label(full_label) + assert short_label == "P14_POP1117" + + def test_indicator_short_to_full_label(self): + short_label = "P14_POP1117" + full_label = indicator_short_to_full_label(short_label) + assert full_label == "Pop 11-17 ans en 2014 (princ)" + + def test_hierarchy(self): + assert True == True + + def test_get_classifier(self): + classifier_name = "KNeighbors Classifier" + classifier = get_classifier(classifier_name) + # classifier == KNeighborsClassifier() fails because they are different objects + assert type(classifier) == type(KNeighborsClassifier()) + + def test_set_classifier(self): + classifier_name = "KNeighbors Classifier" + classifier = get_classifier(classifier_name) + assert classifier.n_neighbors == 5 # default is 5 + + parameters = {"n_neighbors": 10} + classifier = set_classifier(classifier, parameters) + assert classifier.n_neighbors == 10 + + def test_signature(self): + classifier_name = "KNeighbors Classifier" + classifier_signature = signature(classifier_name) + assert "n_neighbors" in classifier_signature + assert classifier_signature["n_neighbors"]["types"] == ["int"] + assert classifier_signature["n_neighbors"]["default"] == "5" + + def test_train_test_percentages(self): + train_size, test_size = check_train_test_percentages(40, 60) + assert 0 < train_size < 1 + assert 0 < test_size < 1 + assert train_size + test_size == 1 + + train_size, test_size = check_train_test_percentages(0.7, 0.4) + assert 0 < train_size < 1 + assert 0 < test_size < 1 + assert train_size + test_size == 1 + + def test_intersection(self): + l1 = [1, 2, 3] + l2 = [2, 3, 4] + result = intersection(l1, l2) + assert result == [2, 3] + + def test_union(self): + l1 = [1, 2, 3] + l2 = [2, 3, 4] + result = union(l1, l2) + assert result == [1, 2, 3, 4] + + def test_similarity(self): + value = "Countyside" + lst = [["Houses", "House"], ["Countryside", "Countrysid"], ["Green areas"]] + index = similarity(value, lst) + assert index == 1 + + value = "Countyside" + lst = [["Countrysidee", "Coutysid"]] + index = similarity(value, lst) + assert index == -1 + + value = "Countryside" + lst = [["Countryside", "Countrysid"]] + index = similarity(value, lst) + assert index == -2 + + def test_get_most_frequent(self): + lst = ["Houses", "Houses", "Towers", "Housing estate", "Houses"] + result = get_most_frequent(lst) + assert result["most_frequent"] == "Houses" + assert result["count_frequent"] == 3 + + # def test_add_assessment_to_file(self): + # code_iris = "692440001" + # values = ["Houses", "Housing", "Green areas", "Peri-urban", "West", "Upper middle"] + # result = add_assessment_to_file(code_iris, values) + # assert result == "okay" + # + # def test_add_assessment_to_file_v2(self): + # code_iris = "692440001" + # values = ["Houses", "Housing", "Green areas", "Peri-urban", "West", "Upper middle"] + # result = add_assessment_to_file(code_iris, values) + # assert result == "iris already assessed" + + +if __name__ == "__main__": + unittest.main(verbosity=2) # run all tests with verbose mode + diff --git a/predihood/utility_functions.py b/predihood/utility_functions.py index fb2eaf4386942a66f50ee741b69db858db5d9b4c..0eee0900014b20b84621796aa24245f3b4e6bd89 100644 --- a/predihood/utility_functions.py +++ b/predihood/utility_functions.py @@ -44,7 +44,7 @@ def address_to_city(address): """ response = requests.get("https://pyris.datajazz.io/api/search/", params=[("q", address)]) json_response = response.json() - return str(json_response["name"]) if "name" in json_response else None + return str(json_response["city"]) if "city" in json_response else None def append_indicator(raw_indicator, iris, lst, append_col, indicators): @@ -207,7 +207,7 @@ def signature(chosen_algorithm): Get the signature of an algorithm, i.e. its parameters, the default values and the type of each parameter. The documentation of the algorithm must be in NumPy style. Args: - chosen_algorithm: the name of the algorithm in str, e.g. RandomForestClassifier + chosen_algorithm: a string containing the name of the algorithm, e.g. RandomForestClassifier Returns: the signature of the given algorithm, i.e. a dictionary containing for each parameter: @@ -286,7 +286,7 @@ def signature(chosen_algorithm): return parameters -def check_dataset_size(train_size, test_size): +def check_train_test_percentages(train_size, test_size): """ Check train and test size and update with defaults or divided by 100 if needed. @@ -349,7 +349,7 @@ def similarity(value, lst): lst: the list containing other values to check similarity Returns: - the index of the similar value, -1 if no value is enough similar + the index of the similar value, -1 if no value is enough similar, -2 if the value is already added """ for i in range(len(lst)): if value in lst[i]: return -2 # this value is already append @@ -395,7 +395,7 @@ def add_assessment_to_file(code_iris, values): Args: code_iris: a string corresponding to the code of the IRIS (9 digits) - values: the values of the 6 EV that represent the environment of the assessed IRIS + values: a list of values for the 6 EV that represent the environment of the assessed IRIS Returns: the string "okay" if the assessed IRIS has been added to the CSV file