← 返回题库
初级

更新分类器测试

未完成 0%
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    data = [
    (93404.0, 13999.0, 1),
    (110890.0, 13995.0, 1),
    (94133.0, 13982.0, 1),
    (46778.0, 14599.0, 1),
    (53106.0, 22500.0, 1),
    (58761.0, 24998.0, 1),
    (108816.0, 24947.0, 1),
    (81100.0, 13995.0, 1),
    (90000.0, 8400.0, 1),
    (68613.0, 14995.0, 1),
    (94000.0, 11995.0, 1),
    (92500.0, 10995.0, 1),
    (112081.0, 11995.0, 1),
    (105121.0, 11500.0, 1),
    (92000.0, 2013.0, 1),
    (107953.0, 12999.0, 1),
    (56000.0, 18995.0, 1),
    (101191.0, 18900.0, 1),
    (64365.0, 16998.0, 1),
    (66000.0, 10000.0, 1),
    (76675.0, 12500.0, 1),
    (93015.0, 15995.0, 1),
    (80917.0, 14970.0, 1),
    (96000.0, 16795.0, 1),
    (70000.0, 12999.0, 1),
    (107000.0, 11950.0, 1),
    (78000.0, 18995.0, 1),
    (78000.0, 15000.0, 1),
    (92000.0, 2013.0, 1),
    (57624.0, 21963.0, 1),
    (77854.0, 16995.0, 1),
    (48310.0, 22998.0, 1),
    (51656.0, 20998.0, 1),
    (62410.0, 19991.0, 1),
    (39332.0, 29995.0, 1),
    (31420.0, 21000.0, 1),
    (41267.0, 22450.0, 1),
    (73000.0, 19999.0, 1),
    (94608.0, 11995.0, 1),
    (67000.0, 24964.0, 1),
    (50000.0, 18985.0, 1),
    (73601.0, 16999.0, 1),
    (50000.0, 18985.0, 1),
    (95229.0, 15980.0, 1),
    (69000.0, 27247.0, 1),
    (73309.0, 13790.0, 1),
    (41573.0, 21970.0, 1),
    (42172.0, 25842.0, 1),
    (41085.0, 18750.0, 1),
    (81625.0, 13990.0, 1),
    (38000.0, 24900.0, 1),
    (65000.0, 12000.0, 1),
    (103000.0, 16495.0, 1),
    (76000.0, 18500.0, 1),
    (34000.0, 19950.0, 1),
    (66000.0, 29500.0, 1),
    (36756.0, 18999.0, 1),
    (42681.0, 26697.0, 1),
    (29000.0, 29997.0, 1),
    (51000.0, 26968.0, 1),
    (26000.0, 25980.0, 1),
    (88262.0, 18338.0, 1),
    (48321.0, 21322.0, 1),
    (93762.0, 16991.0, 1),
    (79972.0, 16499.0, 1),
    (54177.0, 20774.0, 1),
    (43294.0, 21800.0, 1),
    (55736.0, 24985.0, 1),
    (74896.0, 22599.0, 1),
    (72282.0, 20770.0, 1),
    (58328.0, 22000.0, 1),
    (49856.0, 20998.0, 1),
    (42229.0, 21998.0, 1),
    (38126.0, 25998.0, 1),
    (46000.0, 21900.0, 1),
    (95000.0, 18500.0, 1),
    (30000.0, 19899.0, 1),
    (63000.0, 21500.0, 1),
    (39835.0, 27629.0, 1),
    (51043.0, 25964.0, 1),
    (27000.0, 30998.0, 1),
    (39591.0, 25000.0, 1),
    (37703.0, 35990.0, 1),
    (41467.0, 30254.0, 1),
    (83000.0, 15900.0, 1),
    (58623.0, 21998.0, 1),
    (57276.0, 21998.0, 1),
    (27620.0, 23998.0, 1),
    (40237.0, 21998.0, 1),
    (52961.0, 22998.0, 1),
    (36707.0, 34888.0, 1),
    (42363.0, 29891.0, 1),
    (44943.0, 23697.0, 1),
    (90000.0, 11000.0, 1),
    (90000.0, 13000.0, 1),
    (42470.0, 30977.0, 1),
    (27000.0, 20999.0, 1),
    (37000.0, 31990.0, 1),
    (63000.0, 2016.0, 1),
    (51000.0, 2016.0, 1),
    (59014.0, 13995.0, 0),
    (70000.0, 9900.0, 0),
    (84507.0, 14998.0, 0),
    (76000.0, 8300.0, 0),
    (41868.0, 15998.0, 0),
    (40631.0, 13991.0, 0),
    (74000.0, 10532.0, 0),
    (69703.0, 12900.0, 0),
    (37000.0, 15850.0, 0),
    (33000.0, 13995.0, 0),
    (75000.0, 9500.0, 0),
    (35000.0, 11100.0, 0),
    (97109.0, 11991.0, 0),
    (128882.0, 8359.0, 0),
    (39000.0, 13759.0, 0),
    (65000.0, 13990.0, 0),
    (37000.0, 12950.0, 0),
    (130000.0, 9500.0, 0),
    (63430.0, 12995.0, 0),
    (120000.0, 7600.0, 0),
    (74000.0, 9000.0, 0),
    (46000.0, 13982.0, 0),
    (73428.0, 14991.0, 0),
    (200000.0, 7950.0, 0),
    (88180.0, 12998.0, 0),
    (89466.0, 14599.0, 0),
    (76985.0, 11990.0, 0),
    (65000.0, 13990.0, 0),
    (63621.0, 12395.0, 0),
    (96000.0, 7900.0, 0),
    (74000.0, 9000.0, 0),
    (75000.0, 11000.0, 0),
    (143000.0, 8999.0, 0),
    (112000.0, 8900.0, 0),
    (74000.0, 9000.0, 0),
    (185000.0, 5950.0, 0),
    (80424.0, 13000.0, 0),
    (48655.0, 17998.0, 0),
    (102000.0, 9997.0, 0),
    (67508.0, 14991.0, 0),
    (39395.0, 18998.0, 0),
    (44531.0, 16577.0, 0),
    (68000.0, 12495.0, 0),
    (35000.0, 11999.0, 0),
    (68000.0, 12495.0, 0),
    (115000.0, 10900.0, 0),
    (66293.0, 14472.0, 0),
    (141000.0, 10000.0, 0),
    (109496.0, 9677.0, 0),
    (82000.0, 7500.0, 0),
    (106361.0, 10953.0, 0),
    (187000.0, 8800.0, 0),
    (76912.0, 11993.0, 0),
    (117000.0, 9450.0, 0),
    (113963.0, 11494.0, 0),
    (72000.0, 12490.0, 0),
    (71218.0, 11994.0, 0),
    (48924.0, 13786.0, 0),
    (100000.0, 7800.0, 0),
    (98531.0, 10979.0, 0),
    (43015.0, 16977.0, 0),
    (29695.0, 16599.0, 0),
    (44640.0, 16900.0, 0),
    (56478.0, 13990.0, 0),
    (114959.0, 11060.0, 0),
    (83861.0, 13000.0, 0),
    (91314.0, 11911.0, 0),
    (37000.0, 16375.0, 0),
    (46000.0, 14500.0, 0),
    (45358.0, 16991.0, 0),
    (68432.0, 16998.0, 0),
    (37739.0, 19998.0, 0),
    (89352.0, 12995.0, 0),
    (65000.0, 13500.0, 0),
    (61000.0, 13000.0, 0),
    (35385.0, 13988.0, 0),
    (65000.0, 13500.0, 0),
    (57000.0, 16791.0, 0),
    (90019.0, 14790.0, 0),
    (136095.0, 11595.0, 0),
    (27000.0, 16235.0, 0),
    (54480.0, 17910.0, 0),
    (100000.0, 16000.0, 0),
    (65899.0, 16482.0, 0),
    (27000.0, 17734.0, 0),
    (144000.0, 9800.0, 0),
    (26989.0, 17925.0, 0),
    (67662.0, 13400.0, 0),
    (38401.0, 16998.0, 0),
    (80982.0, 13999.0, 0),
    (43000.0, 17492.0, 0),
    (87428.0, 11794.0, 0),
    (34028.0, 17491.0, 0),
    (37000.0, 15800.0, 0),
    (32000.0, 20995.0, 0),
    (89000.0, 12999.0, 0),
    (64000.0, 15000.0, 0),
    (45000.0, 16900.0, 0),
    (38000.0, 13500.0, 0),
    (71000.0, 12500.0, 0)
    ]

    def bmw_finder(mileage, price):
        if price > 25000:
            return 1
        return 0

    def test_classifier(classifier, data, verbose=False):
        true_positives = 0
        true_negatives = 0
        false_positives = 0
        false_negatives = 0
        for mileage, price, is_bmw in data:
            predicted = classifier(mileage, price)
            if predicted and is_bmw:
                true_positives += 1
            elif predicted:
                false_positives += 1
            elif is_bmw:
                false_negatives += 1
            else:
                true_negatives += 1
        if verbose:
            print("true positives %f" % true_positives)
            print("true negatives %f" % true_negatives)
            print("false positives %f" % false_positives)
            print("false negatives %f" % false_negatives)
        return (true_positives + true_negatives) / len(data)

    test_classifier(bmw_finder, data, verbose=True)

示例

输入
solve()
期望输出
true positives 18.000000
true negatives 100.000000
false positives 0.000000
false negatives 82.000000
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码