运行KNN时,“测试”和“训练”的暗淡有所不同

时间:2019-01-07 16:29:48

标签: r classification knn

我正在尝试对测试运行knn并训练数据。我的火车数据包含10000个观测值和33个变量,而测试数据包含1500个观测值和32个变量。我知道由于训练和测试中的变量数量不同而导致出现此错误,但是即使训练和测试中的变量数量不同,也有什么方法可以克服此错误并运行它吗?我已经尝试在测试数据集中添加另一列,并向其添加NA值,但这没有用。

这是我尝试运行的结果,它给了我我提到的错误。

library(class)
cl <- trainset$unique_id
knn.pred <- knn(trainset,testset,cl,k = 107)

我还尝试使用插入符包中的火车使用不同的代码来运行此代码,但是又出现了一个问题,即联系过多,因此我也不能这样做。

测试集

    structure(list(unique_id = c(73928L, 3263L, 28243L, 21565L, 49267L, 
21599L), metric1 = c(0L, 90L, 0L, 0L, 0L, 0L), metric2 = c(1L, 
1L, 1L, 1L, 1L, 1L), metric6 = c(1L, 1L, 1L, 4L, 2L, 1L), metric3 = c(0, 
0, 0, 326, 56, 0), metric4 = c(0, 6, 0, 978, 56, 0), metric5 = c(100, 
0, 100, 0, 0, 100), binary_var1 = c(0L, 0L, 0L, 1L, 0L, 0L), 
    region = structure(c(215L, 170L, 199L, 59L, 63L, 170L), .Label = c("016ea69f855a716ec5e738506d1c6246", 
    "026d694c5c628393fe2d68b47cf1a808", "02d39f8c0bb8a6d74822c5b1325b6d52", 
    "04a5038c780ec3aa6a7124377d14577c", "05b6efe819965e5528b5de4f5a7a8d63", 
    "068a0b5b2858dc3f1ac7b47464bc4b0a", "06fa309b609b7c8f7c39a88abe2d507c", 
    "07fef9bb7fdb75c3be4801cc786d7aac", "08f461425ee5a5fb3197df665459ef97", 
    "090a4cbd8a5951a9b6312ec9491cfbd4", "097f0bcf6c5c038be7e1509b4737b423", 
    "0a394c8282da3440e523469562cfe696", "0b5853af814efb504db07f5bf0ed8d84", 
    "0bad206b82a2c718af4332280419b104", "0cee141d0d8d5eee1a2e57a1bac633c2", 
    "0daaf4a9abe3920c453a7f1f82a9bb19", "0eb635a109be482d973ed1c4a5fbb77a", 
    "0ef8f876d62a45352e28410454e3634b", "0f2a4050992e98c99c88f1b8ea533439", 
    "10da461c3f290aa0aa9883c36f9e4adb", "10e5433a540e0ececbbb2367dbb9eb13", 
    "11ea71f253acf02a2d126a0901e765a7", "130c7ca8daccb66ef614ec3331a0f665", 
    "146159057df3f8947f820d9fc184c6cd", "15e49475e42539feed93fc5cce25d3cb", 
    "1743af44b85a13e7050174fbd749250e", "185a5eb309e9ba14f65e6486f08b3032", 
    "1b86e8daccc894df32394681ebe753e4", "20639b767478006218447b27e4b853cb", 
    "2078da3d3b101e997d874cc9f5686f00", "213fe69502445ed67ae8b99d22838802", 
    "21c2c0aa20f66ce85068ef326d9a792b", "2242bd37650b33ad81da8fa1b53797a2", 
    "23b998b19b5f60dbbc4eedc53328b0c7", "25095ab19a09de4fe2c1f10ee6292e04", 
    "26ba3224ef491b44fad2bb9545bf84d5", "270903eb4969beb28f34647da0ccb2d6", 
    "27559de2125101ccb786807bceb46aa1", "27eb30ceaa63439144a38baeca55f206", 
    "292c955b63b2b9dc0b693c4504d01fbf", "2b29c5739ec4158573c66d2124e2c7e9", 
    "2d567dea4e1ca0874e3684b784cc15cf", "2e2429f5e2bdf4c2f5e178480d79da1e", 
    "30439c5f30ec334054b9a2dd65a3c256", "3135b7017c27d9d3a492a0f5bbd36ae3", 
    "3265469ced1f3458bac306e660889e3a", "333a63bb6200b3c66be6c13d20a6ec39", 
    "33d760dd178036b714669c2766cadf1b", "356779a9a1696714480f57fa3fb66d4c", 
    "35d7df6ed3d93be2927d14acc5f1fc9a", "35f7dca367498da7b80d9a71882491a7", 
    "360928e22038c17d203350022f011d46", "38662eb9d1902f05263ea02bdcd91440", 
    "387589377125beb163bf2d65e5f3212d", "38e7cd9053a8ecf857250c6b1ff5fd9c", 
    "3997a602512adbf8c21e0f73b7f5027e", "39aa18ddaab31b9f4e9adc908059fef2", 
    "39da6b7e3479522718668deaf7e6f304", "3a2d6295a828fc1ec5084af382b61e35", 
    "3b2205b3d8832766c600d5f2f1443aa0", "3cb9b578480dcf52f203554535c12699", 
    "3d147c6ba113929f5a004a5e9dcc832e", "3d4a305ac68921930382976e382dc0a9", 
    "3e670ad8d80b2aea076a0e3521116d40", "3f6765c843a517aa042ae011230aa976", 
    "3fe5003edc0cb6c83962dbd74d35dd50", "403ec7ac6864b855d6111ddb002d1051", 
    "4145cc603ed0c55bb9e0992ff4c7d11f", "4187c4575f19a0b34cb6358c5590a449", 
    "418d4c56f7fa6ee6dbfe42f70876d8da", "42d20f8df13cd6ad6dee44de72d3df11", 
    "43e4db714b06b8a429972d63a47f2e8c", "44e0325f3e4f2272ae44a4a675b527e6", 
    "45009b4a16ef03ba8bb5b15665ef4469", "464f18360a31a99b8003db4c668244c0", 
    "46ba7034d55e0f919de9a812fdd164e2", "46bc56ae264329f72d44b7bfd2f87076", 
    "47b231eae4bf87fa405e34eb9273b741", "48a97757b79e27034f824854ee0f4f46", 
    "48e9e25e522ac6a53144c14e3f45447f", "49355141b988b1bbd2c1b87db70f431d", 
    "49a1e8cf277bb1f58536e45c10c10020", "4a0ade8fc063e6e461708e6a8f2f8f43", 
    "4a8579ed6482f356e7eefab447189083", "4b25e894543db7b2110b0d2e76e82cd3", 
    "4b70ef6abcaca1b3311ccd7636aa92e2", "4b8c5cc6acf242d8a24ad12b227d16ce", 
    "4c936a7800169703f1df5342fa23b659", "4ec96adb9cc39333f3d2024b28f2503f", 
    "50330dc4dd9b35f8c1d7d87737d84246", "5114603603977f3c09f73b83e16d3cf4", 
    "51927f298859f68ad4b6dc0a99947f6c", "519b60be0bda044ee60e537937cad689", 
    "5308f89b85b77bdd39a446f01674e874", "53c438bfa3cd85dab0ca84af9ec94f53", 
    "53fd6c0f288aa0c2c784c4fd0ea73305", "5466ee572bcbc75830d044e66ab429bc", 
    "5503bcea3b608d5ce322ea8fb7f6806f", "552b7b73f4a1385ea6f072c99ff8cd0f", 
    "5618ce87a95a99a4ecb68c80965cb238", "57666bfbae414a8eabfb0060f0b9e2f0", 
    "57cee3de4011057f7b2ec8f4bcd5c523", "5a0228717c1a94a94868e38e8033ef47", 
    "5a580251d6bf2997599549e91c4c1a74", "5aeb407b7ca7f3fe0dc50003b1e0712f", 
    "601f9226a92f0a314068aa4395f65528", "6066310fdf9edf269cb0b6848ddfccb9", 
    "6209f257ee6dbb2bb5f5d607191716de", "62413a57c5e3dc51177995fa175d3286", 
    "62cfab1d81df1897ffaae3094403483e", "6314044c3803213e9fd3f3ecf8c90d65", 
    "643713d97ffe86a712eae5bd4586e804", "646c490db8f1951b717be6816af287e0", 
    "64f607906be7598a02d75dbc1e979662", "66c2b329479ee151b4c6b257c0b7a9b7", 
    "66cf6d100b89d6ceb033ace1b13f25d3", "6a382f5bfa3db109c81ec4adbf70ff26", 
    "6ba317be48c8e9191da834d558ac23df", "6d69689d0056a27bce65398abc70297a", 
    "6e4de336e5285d14ce91ff961be7dbb5", "6ebcc1e9f179c6d99e1ac8a6a5f65709", 
    "6f62c119eb74408b76b9b32e53b38cf5", "6fffa93b10187b587cb4779e0eb6fe5b", 
    "7202aaf1fec09f477ee6ed504f5e457c", "7373ad827161c459c0c09909070d054d", 
    "747bdf95fdef790702c06bee59041e47", "753a3a05136b22cc4a61d6a21956b972", 
    "75831c9c759148cd6ae565676f122364", "75b43a72911661944a58f1e3ea586c28", 
    "779f6f085cd7c0156299c4a2fa799269", "7906639fddcc2c35bc112557ed971a0c", 
    "7be8ea8816327e0c4f8db29e9daa9913", "7c0e2b92f76ed5847aa48a3a1e70ae7d", 
    "7d07b15a160712cc823f7a117fb9b2c1", "7e35e74e610188414ad24235dd787c78", 
    "7fd105a787d357df1f013644ed4df2b7", "80150d09100abb8a34c6233d7bec11e7", 
    "80e72d7a7eb3c03cf07e07c04d5172f7", "813d03d7252a3eae8cb64972f12a2815", 
    "81b03c07e7cc90aabc2143648791ed06", "82b3ef194d59e384d00bbc07214bac17", 
    "83548504e015b34fda641dd142f4b8d5", "84e516108956e6e374941043b5f73e86", 
    "85d2b8ec0ca91db1e0d6ad486c169959", "862fffe658cd2b41e353d36a29bf2c46", 
    "86871c416a7dbed7e5cc229d143d8d82", "873a14db322716c19002987ed35694be", 
    "87809c954948d8a20507bee3648281b3", "87da1803d79be02847802fb26ee3f961", 
    "895be5c71bc473f4ca8de3760cf00c53", "8b3c77aaf3f661b319537ef8425b0caf", 
    "8cb95488fc4103f9830357cfe6953e57", "8cca5c41f36857e6210a1c50cfcd991a", 
    "8ce94baacc570c97dae055b23ea897fa", "8db95c71eae98cf838c50d8916379eef", 
    "8eadc5d3e1f1919c527b6d865e226a88", "8fcebe1ce891c49c60a3c26b317ebafb", 
    "9028ca7fec723c64db485c24a9783719", "904848bc2d46b8dcd2e90e5a025f726e", 
    "917d27ae871df5025edccf1f9df94ca3", "91da6dd9de76a92eedcf2df27297f538", 
    "9221413dd904c157938b397753a8b4bb", "92aec0ba411203aa3a57aec94b108ed6", 
    "97177beec24bd6b78602d0a233d83b07", "980ceec1dba2d36c2ba867f683b47838", 
    "98a0215e7384c0045229405845a76921", "9ab9590a01f804db6f3ae11b1e05018e", 
    "9ac24d086d7592786374e1995fb205e6", "9ac31dfb3a2f5b994f4009eb0a3c0949", 
    "9baaebe1759ba1a6365a2b0539081516", "9c90f1d69dc19cc764573407523bf6f3", 
    "9dbccac1435d0507f0876bc9ad96ab6d", "9ece5daadfe93ee09ab511a2488d9cbb", 
    "9f405b4cfb0722cc0518fc99a26f3c2a", "9f9619c660a78626f2a693ec4ceb2ee5", 
    "a16bacc3c22e820644b03842df178350", "a2db0c3312196037b92893210aa48b4b", 
    "a36a219e6b2e4ee8679237c7a48cf090", "a38fc5ae75908cd961d5a00b1a0cef85", 
    "a5242c1436be2b5a277885df78be6b01", "a5c53b081bf565526eb3779db999becf", 
    "a71105026dfe9155f7ac4d18e494a40b", "a7e95542fe6c4cc634c9d25bce7a5d58", 
    "a8088b760fb315d2964735686800b203", "aa7d335b4e1207d33444473d97b41643", 
    "abedfae798c4d0dfb99495da3dd9f4c5", "ac155afff53711073253a1cdfd42464c", 
    "aed751d76da0e4287401e306bd3aff78", "b08449f484619fb3f3fa75cd3f644c7a", 
    "b0ea6e29d4727582c926ca0e6b9f775b", "b27b7a09b564b9217c42dc7e9acb684b", 
    "b3b43569f42a15f4681b11955b7d9243", "b443dc813722641e3f85b49e2659d578", 
    "b4633fd481929a6720751e6e1a5307a8", "b6111b6a101e80da31bd9fc31655164b", 
    "b61edf09bc11c8646a60601763988304", "b85c8b6c0f7ddac2e9fb14f88ea51278", 
    "ba290ff950475708a10987cb31e6274c", "bdada9e44abf7ffb035f4a8cb5c2c5cd", 
    "c01eba257b2d44afb1896051da9185b4", "c05c86af85b8f0b70f87c92d8cbcd865", 
    "c16c50f34911d1f5d3924c8267409904", "c5376d00573c5858adf7ed894d0491b9", 
    "c8b287075ce4f11c834d2a0ada967ddc", "c9561c4acf174e05975d0ae90274035a", 
    "c966f9d38c7350023d20afdbec522fd6", "cadfc547e9b7404ea03e71b8bb25954e", 
    "cb17153656c01858896be179abd25e38", "ce1c4e1951d00c68e60f09afada9e7e4", 
    "ce5f935e6ec2b08791ec66bc69a951e6", "ce732f2df1ae948926dbbf8a89dcbdd2", 
    "d2b52f8412469a9e89dc546247bd33e0", "d2cda794738b14e5dee201819dd18c85", 
    "d37293d193e6e7e552fe372d123b3725", "d418e699c9dd62a45089899a35a02404", 
    "d57b40ed2e8bc1836a8bcd9c59df477b", "d57e7ab0c562f798b159b148a359d135", 
    "d7a5be172f77453b4400144c8b66df1a", "d8462046af338c2f6df15e812e1d5d81", 
    "d8afff57191b68b3b4f4c3d1099fc276", "da4d1129a255f83fb03bf32fde034ecc", 
    "da5dd6f051ca74960ec199973cf8bf0f", "dbe31edc783dbe62a23d2e5f23d8cf97", 
    "dd9f2d07340a5ea8192fb5eeb34eb95d", "de0962e3808682fdc7855382be6b1ab3", 
    "deb65130918c961ea80790accbb4484d", "dfee9e39474b6e292d66c7facba668e1", 
    "e07cf9eb55f24f169d241ff2442ec37c", "e136e0e47c2879cc794e4bd1890ba902", 
    "e369d9fd2ab54455129816db19e37fd4", "e612e56ca0235a349cffa8331d8a6ad7", 
    "e70e57814ff06fa4c7d23cc39914d614", "e8b307b59121c324d2b58725410eab38", 
    "e9e471e3a4e74166d8eaf8b30e48e0a2", "eab98c0bc6134f56fe729dedf154c26f", 
    "eada819634d0164c6a7547bdcc405033", "ec2891c0593eed8bfa2108fe579b598f", 
    "ed49291dd8535b70546cb15e243ea37e", "ed69c3bd64de0d4ecd3f5bd55fda117c", 
    "ee1611b61f5688e70c12b40684dbb395", "eeaca0ed2f6a35370c77de30792debb8", 
    "eebf071d303bacfe47355045fd217ea6", "efc73cda89606b3705a1ecd081e1388f", 
    "eff4cb54c50b964bd1b69ec173b75e2d", "f212ce4b0b1c7cab9f2b2772ecc69e6a", 
    "f2b705e9bdd7e9079fe90f4196a5d10f", "f3a693cf1392030d179eaa94d226f0ea", 
    "f4830432874f86d2e2a1a5f2dbebbc80", "f4be313e5138fe6c3edae929fe51bc9d", 
    "f7529880ccaf91ff331809e9fe98f883", "f7ee59ee124e09cdf3026469989f0f86", 
    "f861c3009351f54714867a615465e4ff", "fab80a2c9e597d3ad1927c09a2cebb24", 
    "fd38499c5c04df42d1d78807aa4b7d7d", "fd6317498ebab5f40e639003e3d863fc", 
    "febc878157d089972032f2a34c4551b3", "fed4ae5cf6de28514aa160a5942511a6"
    ), class = "factor"), sourceMedium = structure(c(45L, 35L, 
    109L, 109L, 165L, 30L), .Label = c("01960b4f7f9bfa3f80f1ed5b20f4d199", 
    "01d2d639756ecc7681a7332f07a9f520", "02b80b41f1171081efe8bf266cfe4742", 
    "03b57565f7d5b6246426027157f001c5", "080e5148f54332d922bd533d02d076f3", 
    "0b1c546fe5bf75bf8cfe9cc60058f60f", "0c2268be8fff12165a84a412fc6010ce", 
    "0d75546b4828cf84b3b6b183af2397ef", "0ecf3edcb63a7443629e82ba4257d03c", 
    "103501b443f377d26136f55a5476e782", "11d827563b1c18aabbbcb2864a79ff10", 
    "147b55b234c48afdad298584de33d8ba", "14bbdaba26259dd314a0533f67a76512", 
    "1832f3f37179b8c6b94cb76d70fe9e12", "19f1f9af383a75ffb3c8d633a0c21ef9", 
    "1c4874b01cecba4d3475942ff75ebe77", "1d1260e1f8b63234715819386c336412", 
    "1e72e02df57e15dd40d4b755b7f93bce", "21a147fb9fb3f3b0361e22dac2317eae", 
    "21a7597fd88efa4ac08c6497716354b9", "247a016614ea6f35de6707ee9368abf3", 
    "2613a3c6600f45097cb0a0ef8f8313d4", "26b4ec6c200c78b641b7aa11a883cef7", 
    "2703b90b14b98b4fedeb62626d072052", "27c0c5ec272538083b39f0d88dda2cb6", 
    "27d88d08ea1948350eec7c89d4f07624", "29ba84d8df4acf378449d9d2d78fee04", 
    "2a003cac797b6fbeafd35bf98f7f1ad7", "2b0cc0af279485cdebca8b55d6721cab", 
    "2e6b695aaacda04943ae4d70d9723841", "2ed5e1add3733a6dd1ae4e78dc5c2284", 
    "2efc4e9d29404319962e25c420e9e486", "2f6419195abc9222ef7e25c641114e93", 
    "319c3b0bc2fbaa179c2cc1981c06b9ab", "335cceef7d447b13ae8fc7c0e0a7e826", 
    "335d26e195151b8343f1f763574b7bd3", "341f91fe18c8e4870c0eb7764c5cb3ef", 
    "3468729047dec5d3274e8a2fccbc8803", "39b39d96639c889538399d1d3f9e0edc", 
    "3a6f2b8aaa7960cda5b16cf0ad618195", "3b50a221fb7e9a314544e9f2d9375410", 
    "3b98123b7c9b38112a79ebf5f43f8a98", "3caff68e32e893cac1460ec38f01a259", 
    "3dd606e25447c05886f998ea4765bb6e", "3eb1c9693343c41091b1cc671e77425e", 
    "3ef02aa6ca0cba57f6a6dc8ac1931dfa", "3f47e0030851ceb89332031739d0b8e6", 
    "3f891d7a2fe0b9295da4d974730612e1", "41361db67f4753f4667abdfbb2d4f97f", 
    "41deecda62112663128563fa10a79ddd", "42a18c5d620ceb2a87760ed0495062c1", 
    "42b343a41db1ce03cbd952a27ecd6f17", "42d753967ff4df18f93290e8929fbfcc", 
    "44e5e05384a89492d1bd3657a178829a", "4566a927433ac7f16c46b5f3d0e2262f", 
    "4658fa7df810bb6eed8f5cad1c24aa98", "48fe2891d7c7ff654955a179d09fa004", 
    "4b5763c1b0f221e5f07e5f3ced4ba89c", "4da4c82232f42c7553cd94f983d64924", 
    "4daff9df10ac4828800a022acb5bc035", "4f72a52dcef48eff2e840dc2eb0ddf13", 
    "4fda826e7c315cc730816062478527e6", "50f79fdae7abb40934bd59481190dacb", 
    "5185644aeb308b1053ac3f758cf77087", "51e5f63e2f11a83546d44d0c1bd289f8", 
    "55b21533d33a38b75e376a0e6fdc27e5", "5723f7b618e5401efcb7525e64ace972", 
    "588d9be96d22b87aed22321010dad378", "59282963b9534097e2f36ffa57a4170d", 
    "59a86f4f99151da193cae7604f24a8a0", "5b650ca0d874951734e67988ed9105c8", 
    "5cf99569246af9579ccb0a305c5733ae", "5e28142e46be0fea8b67050037a01edd", 
    "5e3e9b426f1af52659714446553ed79a", "5f5b30ef5e85c5d9b1e37d778f9c3f0b", 
    "5fb006258afe2a8042643cef7cb586d5", "61707f5e30653a22bf7de2a3276419dd", 
    "61ab6cd2b9f1163f40216f36b4ec4cc5", "61f7bc69cfad712bc7e8d91e6ed03d7f", 
    "6368e6a61afb7d2ed98e8acfc3cedfe6", "688800b5e0670a68fe889db1a2dc7d47", 
    "68a1274763c83a2d9def7b052d69e624", "699307ad40e158535537affb0097a3d7", 
    "69b309d21cb603dc4810a46282e8b1e3", "6b07404115f1c53b2c84d5a12cf29474", 
    "6ce32f80920f42e7e5b25807e360b439", "6d5fb101a888ff221c316220619cd34e", 
    "6f64c98d1794d6c47b882bdec13b080c", "705d2f8f064089031903f6d575201017", 
    "741fa8e2e3fefaa8297154431c60e7b8", "755107f7668ba72d0555799087706ee5", 
    "75a749a9012ada3b825b4a1b78803244", "76fa2da4831d5b7c74153fc8344e5df5", 
    "77ddb1d74e6f5fdd61c60763e89ac745", "78a99fb6f46a79afc41239d17c38adcb", 
    "79bd2aef037d24a473273ca545bb641a", "79dd4573fafa149a4c2e7dae613bd6ec", 
    "7bc1b05af3e59fa5d8dd97c08313feb1", "7c6dcc356a76759fb32da9bbb659d0aa", 
    "7ccaf9f8e8ec1f70a894d3f111285d47", "7d279c854082d7529bc4bb8d775e029d", 
    "7dc8fc8d0a54892b131dabccc9feaf3e", "7dce1c492c97885cb3b35dff2dede2b1", 
    "7e4331037ea4eadccd355446ffb56f66", "8002adab653b0ecaa73279e2d9e5fd15", 
    "81b0500ff0e375239a9f6a852329e98e", "8269c4eb932ed956c80bf9a2480ffe9e", 
    "83aef05a1655cfe8ee3e85ba045950a1", "889d84a5edb2e81474150e2e6478162e", 
    "8a63b02e349250db0f95bd3fb4e2ee00", "8b218a0eeddafde6b2207a4c59c12092", 
    "8d5bf6fd254591201369d34297543dd6", "8fab519a7155ab4f6b0b2ea7691dbd6d", 
    "92db329e2e79a701dcf6253848da095c", "93f5ae28f058e3ff840cb54f534d640f", 
    "947060d72387fca771ddf93ccded1402", "95c9a8edde16780f2887129e1ac1fe40", 
    "966545719307ba1384d720a02abffcb8", "970d1b58c91c2a2e1be54d2b5c9a3a65", 
    "992d806215968b1e9ab1a30bab3438f2", "9e58f6050e4a71ef74c51f976a50ef7d", 
    "9e9917d2af3ff7809659be5ada7a0990", "9faf8e225b6fd80f6f911839ccd60bc8", 
    "9fd0de8990deaece8b7dceb300d0cb61", "a002273b5de79fefb98a2e629e7cf8c9", 
    "a027c3d449306e157c91606894fe9220", "a0e482a127e5b534e3bb66f18b73a63d", 
    "a2a86326173903241946b1d4603366a4", "a3506e89a3d10d8d649af9cf0d69fed7", 
    "a3ae9d9d6c4d1185b19d00823640b22f", "a437cf83c6bc246e2ab8ea21e785f6b4", 
    "a486c8a7b6db071eb35a8e5e699ea2fa", "a6f7fd25b065e4c4dc8ebca41a48ad6b", 
    "a8e36ba4a9b6991534c62a393eeeb9ed", "aad4be12fcd1847c07d1fb852d74b7df", 
    "abd482cf062523225efcbd5d8b9bcfa2", "b0db58b832616186cde19d9fd2323f0d", 
    "b305c3da2f7045f1eaf8046a44318336", "b594d56f27a7c51b94a2c27d73205108", 
    "b8faace80987811051a0291ad77c828f", "b9172b0eb8f13048c09794c4af6f6924", 
    "b93a209c7a5a764091573b2ba627ad85", "ba880faf5b9f52f04a06662af150f0b9", 
    "ba9bdf78daf12a1066f64afa5f6706f3", "bbd768e0abf66a43f6610282dd56d878", 
    "bd240879dbd47c912f1a71d083cac984", "bd602528407033e9da00f383ea1abed6", 
    "bdd623a9d4a0fa44d36438b42dfcd095", "beda672009495ad92ca2fde650aca190", 
    "bf9d8a99cc2ce2803e2953d85d64f7f8", "c4348cb124ca78627ea9414fb8d10000", 
    "c4ae1bba53003bab413546155a424690", "c55dffc8bde30c50c4302316ca12ab69", 
    "c736a948ae1aa795a50e9b87ef6360b3", "c7becf82bf26565280ad4e2b3714da7a", 
    "c8f5d47905cc5fa795b11c68a560b7f5", "caea27cf62853aa9cd2d6fe9caf22d1f", 
    "cc3c6de52f28cd821ee4414c07344d68", "cea56860397057a3247635b494d44f21", 
    "cf79649970e8b6e6c15cc24793159f27", "d052455ef43d6ce7d2c0ed6e8176ef6a", 
    "d0b68289e5fa95c5b1cf936aecab6ee5", "d194cfe77312e07a39a270fcf29e0575", 
    "d34af648dd12373ee7e4f856ee778d57", "d3d55c19deb05c118cfed68910a1f6bd", 
    "d3f4bf7dee07d0b3d1a9334a5f27f727", "d48419952a1e66959fdbe24c23485845", 
    "d54b1372503b8229d2e3356d8d944b9b", "d82aef7aaac77d71786b7e63bf78bca7", 
    "da49a03ee11babd2dab310e5b854e32a", "db338cec56f7440f9952aa0c2f83a08b", 
    "dc812fd581d741ac7ae23743509e5ba5", "ddcb93153a2d1a0b8a124c4c41e917e7", 
    "de0f1860e31efdd412879ac5aced1154", "de20b1511dd8dd3a178bd12fab48a947", 
    "df258aac52ab6adc81603b86b1406632", "df3de6de64ea728b13ff82d8de150efa", 
    "e11f84c6d0a32c978faf4b54442e8dd2", "e35c8ed17a99611a631ea86746869323", 
    "e3c41ddd60be4a6b2d2184a033fcafd9", "e481151a41ccea2cb3f34936c9afede1", 
    "e4ab078ee0e14f35f8e82ae2164b7e2b", "e76a324208db8ac0c62b99fde917dc4a", 
    "e786ec4e49def3b9341500353b63899a", "e8499a90201c712a12eae33169a940a2", 
    "ea5a39d9a5e7a816623cf016e1dafae6", "ebf54b7baad470799b02007463c81563", 
    "ed8856a82ec1b312c8c6a876288d0bdb", "eda4700cd56228fa0cb179442bcff2ef", 
    "eddd745dec1ef8a970ed70641560b92b", "ef21e4a65633d49c65d89a78c8fa3153", 
    "f3d6dcd1992b300d710f75b84b6bf6d7", "f40772e8eae3cda18bfa916a7e256ea6", 
    "f5a8d7f5be5ad403cabbf83a9cd83ce0", "f600db9cfc6770c7d414f49c148a0237", 
    "f878fa19a21ae1abec60461f7aa68c81", "fd15704f09953d8126d1aff7df808f69", 
    "ff78bbcb686c5721cbfc2b236afc450e"), class = "factor"), device = structure(c(1L, 
    2L, 2L, 1L, 2L, 1L), .Label = c("532c28d5412dd75bf975fb951c740a30", 
    "b2c79ad7dcf03ba266dc0885e1266675", "c4e0ba5422383082417c5f96ab121575"
    ), class = "factor"), country = structure(c(56L, 56L, 56L, 
    56L, 56L, 56L), .Label = c("01a151debf2bfee8906f43f4342eb10b", 
    "0309a6c666a7a803fdb9db95de71cf01", "05387f3ca38d7bd84ae35f31f2899ecf", 
    "06e415f918c577f07328a52e24f75d43", "07f3ca235faaa1c9ad16facef5526d8b", 
    "0a6355f86240762961997e70c5e7087d", "0c12f5495afe76d9242ed25668979de9", 
    "0c7d5ae44b2a0be9ebd7d6b9f7d60f20", "1007e1b7f894dfbf72a0eaa80f3bc57e", 
    "100c93c03f6630aef97e0afc06a6df12", "103357e3e40a9c0e4e9d36110f7bbc7a", 
    "11be385e6740fa25f61ea6b3b10edf4c", "1add2eb41fcae9b2a15b4a7d68571409", 
    "1c77b9733832da9d1ffac66620f3c006", "21fc68909a9eb8692e84cf64e495213e", 
    "221cdfb73049678e244380b45872cbb2", "2e6507f70a9cc26fb50f5fd82a83c7ef", 
    "2ff6e535bd2f100979a171ad430e642b", "31e7e8bf65a10ae8798adfbd8c0cd8c8", 
    "3536be57ce0713954e454ae6c53ec023", "3ad08396dc5afa78f34f548eea3c1d64", 
    "3e670ad8d80b2aea076a0e3521116d40", "3f0e49c46cbde0c7adf5ea04a97ab261", 
    "424214945ba5615eca039bfe5d731c09", "42537f0fb56e31e20ab9c2305752087d", 
    "4442e4af0916f53a07fb8ca9a49b98ed", "445d337b5cd5de476f99333df6b0c2a7", 
    "458e4cbc78201c1aec5fc53a31c59378", "4647d00cf81f8fb0ab80f753320d0fc9", 
    "4be25f9d27da71d4e98775668b5b12af", "4d4803b0bb7dab1b0627e4f8277edc5b", 
    "4d4a1722d8e85909a576da2c42878ff0", "516cc143c53ff93ff3402c323ff23e15", 
    "53a577bb3bc587b0c28ab808390f1c9b", "53b3c88ea00c4f0e137b4e6fe7bd23f1", 
    "551fe18ef47d4e6e9d943b9a68ada21d", "575b9408b6daa2ddcefbcf6d81c9b4c9", 
    "5a548c2f5875f10bf5614b7c258876cf", "5ae2ff99743a8487c917e98bbf3db2d3", 
    "5d839147c83e283c1d1bb705dc50586f", "5e4a24f76c22f03700b283dfbdf6eec1", 
    "5feb168ca8fb495dcc89b1208cdeb919", "62235142f3fca96e1f2cd0ed4a7de48d", 
    "672566a43483aa8212cb365658600b99", "69f4287626aee77f93e2c891b518838b", 
    "6c1674d14bf5f95742f572cddb0641a7", "6ddecd8ccd9f648d19dc02c7a566cb4f", 
    "6e9767f4f15357401b148b9a8ced14ef", "6ea1e24d60afddf388b06f8243c45b70", 
    "6f781c6559a0c605da918096bdb69edf", "7176f8c3bccfdf02322c73f7a0bc9688", 
    "742b8abe5776a6d942a92ce7dc7d84a0", "77dab2f81a6c8c9136efba7ab2c4c0f2", 
    "7c1a943bf29d2c753fb935e99428482c", "7cc7ef17c45527cf90fcf27516794d21", 
    "7d31e0da1ab99fe8b08a22118e2f402b", "7fef6b003c726890ea5ca3708fe8ff56", 
    "84c8fa2341f7d052a1ee3a36ff043798", "88a392b5a8d8f73986d83a2deefb0472", 
    "89f9c9f489be2a83cf57e53b9197d288", "8b476ff778119b8d49588f3daadf69a1", 
    "8dbb07a18d46f63d8b3c8994d5ccc351", "8f6f28f0d2061af28bcf49d1725b2cbd", 
    "907eba32d950bfab68227fd7ea22999b", "921855f753932de762b780405a50bdf7", 
    "92468e8a62373add2b9caefddbcf1303", "94880bda83bda77c5692876700711f15", 
    "94984a8c4896946d9bafd24959cb6181", "9891739094756d2605946c867b32ad28", 
    "9d5116a2451bc98c2b46b93acbc1b4f0", "9d6c9d893aa285a736aeabb2b66b316f", 
    "a00c273f0f497484093fa94865cf5ca5", "a09f4b2ae67f0a63ab8912047a1a1b55", 
    "a67d4cbdd1b59e0ffccc6bafc83eb033", "a6d3bea3fa66775952e080b90bb0c4f1", 
    "ae54a5c026f31ada088992587d92cb3a", "b0aa0804e676a38255af4fd70236af7c", 
    "b835b521c29f399c78124c4b59341691", "b88959cb7d907d91065ac7ec19eb0b44", 
    "b9698b8546220246fe600a949db326bf", "bdde0543f19349a336db0b43776bade4", 
    "c03b1123e45fa00da3142e0424ee5eec", "c51ed580ea5e20c910d951f692512b4d", 
    "c856565f38d8ed5dcc6e4ad20f226045", "c89bc418c38da77213c6c6e03cac2510", 
    "c8f4261f9f46e6465709e17ebea7a92b", "d2e4449b45608e33e472d939a73868f7", 
    "d5b9290a0b67727d4ba1ca6059dc31a6", "d8b00929dec65d422303256336ada04f", 
    "d9051e0b77f8bb5521389618e70e2ada", "e299d7cb0f7866cce7d90da2af14047c", 
    "e31959fe2842dacea4d16d36e9813620", "e65a0ed0e39dd14a9e5af441efb09b37", 
    "e7400496f1ce70cb62c2c44ca2ddc469", "e95294b730f61c8175550ec244bfcb50", 
    "ea2ba3f8011e19e3101ce65fdcefbcc4", "ea71b362e3ea9969db085abfccdeb10d", 
    "ef3388cc5659bccb742fb8af762f1bfd", "ef547e2d9750443f6d203233dfa38e39", 
    "f01fc92b23faa973f3492a23d5a705c5", "f253efe302d32ab264a76e0ce65be769", 
    "f670d3806d530c3e5cb1f31dca457751", "f78a77f631d275aac6a914a17fe1b885", 
    "fceb5af40df295d85851f390f4f8d78d", "fdef6daa799e80dbce1b561577b21181"
    ), class = "factor"), dayHourMinute = c(2.01711e+11, 2.01711e+11, 
    2.01711e+11, 2.01711e+11, 2.01711e+11, 2.01711e+11), binary_var2 = c(0L, 
    1L, 0L, 0L, 0L, 0L), page1_top = c(0, 0, 0, 0, 0, 0), page1_exits = c(0, 
    0, 0, 0, 0, 0), visited_page1 = c(0L, 0L, 0L, 0L, 0L, 0L), 
    page2_top = c(0, 0, 0, 0, 0, 0), page2_exits = c(0, 0, 0, 
    0, 0, 0), visited_page2 = c(0L, 0L, 0L, 0L, 0L, 0L), page3_top = c(0, 
    0, 0, 0, 0, 0), page3_exits = c(0, 0, 0, 0, 0, 0), visited_page3 = c(0L, 
    0L, 0L, 0L, 0L, 0L), page4_top = c(0, 0, 0, 0, 0, 0), page4_exits = c(0, 
    0, 0, 0, 0, 0), visited_page4 = c(0L, 0L, 0L, 0L, 0L, 0L), 
    page5_top = c(0, 0, 0, 0, 0, 0), page5_exits = c(0, 0, 0, 
    0, 0, 0), visited_page5 = c(0L, 0L, 0L, 0L, 0L, 0L), page6_top = c(0, 
    0, 0, 0, 0, 0), page6_exits = c(0, 0, 0, 0, 1, 1), visited_page6 = c(0L, 
    0L, 0L, 0L, 1L, 1L)), row.names = c(73928L, 3263L, 28243L, 
21565L, 49267L, 21599L), class = "data.frame")

这应该适用于火车

https://shrib.com/#_dDy_PjW1lVGl5lTskZM

1 个答案:

答案 0 :(得分:1)

据我了解,某些功能仅在String age = "My name is John and I am 18 years old"; Matcher matcher = Pattern.compile("My name is John and I am ([\\w]*) years old").matcher(age); if (matcher.matches()) { System.out.println(Integer.parseInt(matcher.group(1))); } 中可用。在这种情况下,只需从trainset中删除多余的列,因为它仍然无济于事。这是因为trainset没有进行任何实际的培训;看看我的other answer

简而言之:knn在R 33 中具有矢量,而trainset在R 32 中具有矢量。然后,testset几乎唯一要做的就是计算这些向量之间的距离。由于knn没有其中一项功能,因此我们手动执行的操作只是删除testset向量的一个坐标,以将其缩小为32维,然后计算距离。但这与简单地运行

相同
trainset

如果说第13列是多余的列。