From 99da7c018dd5954a70876d642f35ec9c197cbf56 Mon Sep 17 00:00:00 2001 From: Wojciech Jarmosz Date: Tue, 18 May 2021 23:01:50 +0200 Subject: [PATCH] Add linear regression model and results --- .gitignore | 1 + dev-0/out.tsv | 1000 ++++++++++++++++++++++++++++++++++++++++++ linear_regression.py | 31 ++ requirements.txt | 10 + test-A/out.tsv | 1000 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 2042 insertions(+) create mode 100644 dev-0/out.tsv create mode 100644 linear_regression.py create mode 100644 requirements.txt create mode 100644 test-A/out.tsv diff --git a/.gitignore b/.gitignore index 336d663..529f0d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ *.swp *.pyc +env \ No newline at end of file diff --git a/dev-0/out.tsv b/dev-0/out.tsv new file mode 100644 index 0000000..4399db6 --- /dev/null +++ b/dev-0/out.tsv @@ -0,0 +1,1000 @@ +80410 +14322 +51118 +16995 +25183 +79781 +47955 +11525 +-5348 +17010 +27481 +83471 +7797 +4808 +39068 +24877 +63737 +95380 +40459 +8421 +2497 +10570 +-9392 +59446 +-3562 +71090 +81244 +15360 +11942 +40208 +76614 +65294 +7776 +51832 +40765 +61195 +35783 +26024 +43848 +71980 +77624 +32496 +40153 +69066 +15801 +124148 +93563 +14085 +40976 +53155 +75810 +-6564 +98077 +41765 +13460 +-5587 +-2960 +27657 +72048 +24193 +64726 +-8925 +3363 +75068 +84822 +32852 +-5337 +89745 +34209 +4479 +21400 +35265 +22611 +20874 +169567 +46782 +66234 +43113 +70461 +18250 +48572 +24226 +48755 +19503 +19431 +23242 +59861 +42028 +44693 +25439 +43694 +36666 +59022 +46478 +5458 +6491 +66025 +64371 +40569 +31081 +7607 +6288 +13559 +22128 +8439 +28383 +29626 +45634 +65412 +21787 +79593 +-14498 +55480 +61808 +12042 +41735 +13844 +37718 +56878 +28461 +25692 +33897 +-20913 +33176 +67719 +78607 +-19082 +45846 +23663 +48188 +15442 +-6466 +46850 +39803 +-24799 +65169 +100049 +57881 +34365 +64864 +19021 +53339 +71521 +19386 +67976 +54040 +95037 +15784 +11930 +58565 +35678 +20935 +49646 +-35218 +75666 +-13154 +76540 +22045 +59292 +61340 +38301 +70091 +9280 +-421 +4873 +-8520 +44035 +39918 +27468 +83973 +64399 +73001 +21598 +23790 +78001 +39891 +77601 +97771 +82765 +77624 +57324 +35185 +17808 +-10907 +22751 +7463 +82252 +41402 +12474 +25441 +-10949 +43142 +46348 +64696 +4545 +55738 +43309 +60499 +24551 +38337 +102588 +98348 +-2118 +-13743 +21274 +24634 +36541 +66595 +69682 +36123 +27463 +9141 +94112 +45807 +38539 +79229 +51194 +63795 +122222 +57059 +-13502 +34886 +28541 +-7936 +40795 +28506 +2023 +42372 +42319 +55297 +8262 +46122 +28891 +48774 +-102 +6657 +74130 +51447 +15970 +63486 +40606 +26890 +24890 +50662 +38331 +16862 +15377 +45264 +32982 +14488 +56011 +26566 +50166 +75396 +15105 +88256 +34794 +84563 +36182 +23137 +68839 +11294 +22905 +17544 +75223 +28147 +12 +98265 +3732 +20634 +-10490 +25096 +19875 +20927 +70814 +19296 +19249 +149444 +23283 +26375 +122204 +63495 +14787 +17157 +77788 +32937 +82248 +11154 +35952 +59363 +28749 +73774 +42269 +2696 +30354 +38458 +46926 +31848 +31601 +56576 +25729 +13615 +4902 +37858 +15536 +37136 +9413 +54018 +40874 +12366 +6817 +-21553 +27806 +-17378 +71710 +90435 +4267 +29824 +49562 +29217 +47518 +53054 +28060 +19025 +59713 +79927 +21649 +47733 +64419 +33803 +30548 +66436 +7680 +36104 +-5147 +44328 +44973 +33280 +54027 +67065 +132570 +88117 +46440 +69546 +15081 +65688 +16567 +5943 +55711 +43232 +59470 +16812 +49663 +34348 +53332 +67288 +11415 +7962 +56206 +23327 +98506 +44871 +2484 +52022 +55957 +81238 +179270 +70149 +57143 +12422 +33106 +35108 +-20534 +72847 +84523 +44394 +26109 +51094 +79257 +39524 +-14438 +42003 +37555 +53926 +-32 +29253 +21862 +-13394 +28171 +2672 +51003 +72873 +49982 +26045 +10293 +66290 +25307 +71946 +43336 +36044 +52764 +41238 +89361 +62552 +54602 +27821 +1612 +22972 +81753 +83102 +46789 +8493 +22436 +238622 +101140 +123755 +114931 +11719 +46603 +50958 +46409 +69552 +69213 +81237 +62003 +50624 +53645 +-24318 +56315 +44665 +42636 +76503 +59921 +30071 +8114 +75733 +22129 +43575 +29719 +68659 +33170 +60713 +26725 +69984 +64399 +115713 +45056 +99399 +67277 +67991 +65185 +31389 +7921 +21118 +28048 +50302 +12870 +65919 +54141 +34348 +78663 +17170 +28591 +26298 +11788 +40712 +14642 +85698 +46264 +40513 +28665 +19272 +80029 +73494 +25307 +55617 +31379 +23615 +16500 +62209 +-25892 +47405 +24823 +24354 +18844 +28898 +55693 +51212 +36608 +29213 +47261 +51349 +81238 +26208 +20776 +38692 +64426 +44767 +80125 +1418 +65533 +30339 +38348 +29159 +62853 +62396 +67651 +9777 +90185 +33725 +-28633 +106887 +76779 +22186 +196426 +53668 +20215 +49520 +37178 +-27344 +24311 +54037 +107725 +18712 +27476 +95891 +-10095 +95183 +74380 +69729 +61291 +29958 +98517 +15345 +82047 +13459 +71781 +3895 +68185 +45746 +76472 +70358 +31463 +-522 +13655 +6540 +48452 +21200 +69121 +72862 +53251 +57619 +13720 +30357 +20070 +6026 +18511 +-9642 +5139 +55271 +138658 +87248 +4984 +42858 +42955 +-25442 +57774 +20973 +-1709 +2837 +75662 +38286 +95919 +66880 +85506 +57042 +50228 +91832 +31367 +66899 +-3156 +59106 +-18113 +61856 +73403 +15847 +9605 +39437 +67353 +20024 +1248 +25698 +75565 +16789 +49241 +65301 +68921 +129748 +53420 +5720 +28892 +72123 +45560 +64241 +17410 +35750 +14783 +-45085 +26248 +59500 +48483 +19907 +80 +58338 +46505 +44274 +27615 +23818 +55055 +43443 +201641 +18485 +-16156 +58552 +41653 +17495 +41891 +51666 +12237 +73580 +-628 +134770 +91510 +127 +27778 +1182 +31943 +675 +69719 +27013 +42141 +-5269 +23093 +26278 +36395 +23286 +51525 +36019 +61173 +57702 +57628 +24984 +28703 +44814 +63992 +25751 +59102 +90941 +91019 +43865 +54575 +2787 +47255 +27165 +37769 +41292 +19038 +17499 +12015 +90985 +51847 +34356 +9818 +90416 +28048 +36281 +33291 +81097 +32205 +47623 +-34890 +40158 +19170 +119529 +76608 +52509 +67067 +32530 +39479 +-5972 +12381 +13931 +11493 +55250 +48871 +3333 +-15323 +96171 +-468 +72417 +211 +34486 +97899 +43675 +25304 +52378 +61404 +99580 +35457 +-14177 +16163 +-27059 +23126 +54194 +8252 +37064 +-9206 +61546 +129410 +50148 +62257 +983 +43179 +59715 +-2148 +-1092 +56671 +15205 +23850 +-766 +30596 +81036 +106151 +17925 +2842 +84794 +1098 +29001 +21878 +5639 +27765 +23041 +94404 +64512 +720 +50187 +53391 +45518 +57871 +17855 +61013 +-28439 +46730 +76814 +5511 +71709 +45335 +-11533 +-40403 +33312 +14093 +16659 +27512 +110034 +30124 +47260 +30592 +34368 +-32654 +44842 +-23410 +38028 +35564 +39112 +55143 +10586 +-23469 +21379 +43556 +19513 +23776 +40001 +-58294 +63741 +50496 +8120 +74076 +60869 +28961 +14874 +61446 +8438 +-5477 +38317 +174650 +-14201 +22005 +81696 +64399 +20911 +-10685 +10042 +63661 +17100 +25686 +4737 +30614 +38752 +59122 +74645 +-4639 +61789 +76892 +7394 +40876 +28525 +16776 +8696 +80303 +59715 +37858 +30856 +6658 +39325 +27287 +69719 +48219 +-4182 +59713 +93795 +24446 +50100 +54485 +76728 +6107 +46668 +60593 +17087 +-7661 +49759 +24212 +41361 +66560 +41808 +6305 +40368 +34129 +67245 +22086 +24401 +31996 +34786 +30608 +58746 +64334 +60408 +13117 +51525 +23556 +-4981 +22126 +16591 +-7523 +45399 +23377 +-13211 +23421 +23634 +32799 +17677 +72048 +52073 +37792 +38817 +11275 +99581 +45846 +128465 +64386 +76435 +37323 +28341 +63242 +19627 +41980 +82435 +47098 +53037 +98027 +11989 +4968 +28018 +1472 +26655 +41332 +-52729 +40133 +-14910 +61455 +82387 +53407 +30966 +81238 +52 +28730 +42977 +-13967 +19111 +46297 +91251 +62018 +118893 +96772 +63100 +24200 +-13270 +29973 +19163 +27931 +30727 +91974 +81320 +2595 +31789 +74920 +79736 +99063 +37220 +16711 +16850 +61040 +45796 +30905 +58921 +17107 +40176 +68556 +82918 +62729 +58316 +-6056 +-12741 +31002 +90231 +43549 +73982 +65229 +-11211 +8557 +89478 +31576 +38469 +11570 +-4165 +36045 +66443 +71639 +22160 +22254 +22366 +6022 +62019 +41278 +85489 +70189 +21879 +22904 +73886 +76768 +7964 +57887 +75408 +49944 +43781 +50167 +38184 +1121 +77624 +26161 +7938 +47213 +78635 +77433 +6209 +8927 +16241 +69194 +79801 +70350 +41169 +36762 +8160 +47339 +48839 +-25660 +19654 +73326 +75456 +44299 +120124 diff --git a/linear_regression.py b/linear_regression.py new file mode 100644 index 0000000..d493fae --- /dev/null +++ b/linear_regression.py @@ -0,0 +1,31 @@ +from sklearn.linear_model import LinearRegression +import pandas as pd + +def prepare_data(file, type): + data = pd.read_csv(file, header=None, sep="\t") + for c in data.select_dtypes(include=object).columns.values: + data[c] = data[c].astype("category").cat.codes + if type == 'train': + data = pd.get_dummies(data, columns=[4]) + else: + data = pd.get_dummies(data, columns=[3]) + return data + +data = prepare_data("./train/train.tsv", "train") + +data = data.loc[(data[0] > 1000)] + +price = data.iloc[:,0] +training_data = data.iloc[:,1:] + +clf = LinearRegression().fit(training_data, price) + +with open('dev-0/out.tsv', 'w') as writer: + dev_data = prepare_data('dev-0/in.tsv', "dev") + for result in clf.predict(dev_data.iloc[:,0:]): + writer.write(str(int(result)) + '\n') + +with open('test-A/out.tsv', 'w') as writer: + test_data = prepare_data('test-A/in.tsv', "test") + for result in clf.predict(test_data.iloc[:,0:]): + writer.write(str(int(result)) + '\n') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f9a4c95 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +joblib==1.0.1 +numpy==1.20.3 +pandas==1.2.4 +python-dateutil==2.8.1 +pytz==2021.1 +scikit-learn==0.24.2 +scipy==1.6.3 +six==1.16.0 +sklearn==0.0 +threadpoolctl==2.1.0 diff --git a/test-A/out.tsv b/test-A/out.tsv new file mode 100644 index 0000000..93d8b27 --- /dev/null +++ b/test-A/out.tsv @@ -0,0 +1,1000 @@ +26157 +27555 +13839 +-7723 +-2132 +22592 +41965 +21547 +120156 +51129 +-27560 +46371 +-3668 +32466 +-23123 +-5269 +47201 +68436 +37206 +17003 +61732 +20411 +-3724 +45983 +7150 +27237 +39819 +38463 +78053 +30008 +43817 +23655 +25128 +12421 +72325 +15805 +55162 +47654 +72747 +38991 +11697 +53460 +38874 +71281 +67499 +35575 +40226 +10662 +29661 +44138 +42675 +87889 +14490 +49094 +-1763 +34218 +67701 +34208 +73689 +99661 +23059 +81924 +67268 +29432 +63425 +71133 +-3853 +-978 +44000 +81238 +53093 +95380 +31177 +79768 +48517 +21858 +24450 +17196 +88506 +31612 +19482 +47269 +65524 +48210 +43307 +78086 +88489 +20038 +35191 +50234 +15561 +62633 +76465 +48705 +22613 +76030 +23887 +11668 +67611 +41702 +77788 +57900 +8214 +30129 +34157 +70957 +58284 +5291 +46665 +20990 +28506 +1925 +61815 +19099 +7208 +81123 +2818 +79020 +-7896 +48039 +23722 +14970 +37107 +224 +16541 +18839 +31427 +5520 +63404 +45993 +24309 +19179 +37698 +9569 +112758 +76679 +31155 +49091 +55517 +33534 +38937 +30515 +45686 +-19052 +35561 +25420 +123830 +47183 +35459 +12563 +62677 +76453 +75774 +31115 +-5560 +121094 +47701 +28410 +43728 +26770 +24155 +19504 +58638 +-7486 +63361 +47134 +27843 +69077 +46770 +64541 +62897 +3607 +27120 +56489 +59865 +17821 +38529 +62631 +83365 +66107 +47816 +52731 +25664 +98277 +55243 +75066 +36756 +40612 +96333 +24386 +27036 +13394 +5366 +21006 +19207 +12880 +57655 +46860 +11835 +43584 +99972 +29394 +23885 +60417 +79448 +67219 +21799 +12514 +37605 +19681 +26600 +-14099 +26207 +42601 +34882 +4233 +56440 +29914 +42100 +15453 +27577 +14802 +74971 +9739 +-6315 +9063 +-10818 +59384 +16567 +54198 +-30600 +4345 +56583 +65478 +44693 +9937 +49627 +27474 +59981 +55790 +-23894 +32 +63945 +-9471 +21802 +30547 +54008 +121514 +47162 +39780 +21843 +43274 +70887 +60514 +61548 +74010 +19763 +41001 +81238 +91125 +27973 +87394 +71466 +3667 +58424 +34671 +31899 +48323 +13453 +68494 +28685 +9248 +39959 +72744 +-532 +6915 +17191 +21962 +83615 +50265 +45312 +21648 +56160 +48565 +36947 +42799 +59476 +81238 +4012 +44416 +36859 +43175 +38331 +25577 +48358 +14630 +50426 +49833 +30907 +46560 +87913 +38001 +112525 +73527 +96053 +63643 +44557 +5154 +82538 +29695 +40316 +-2423 +57901 +55451 +14322 +67062 +28220 +-10083 +40697 +45502 +71969 +43354 +91899 +20544 +17288 +93326 +36070 +24981 +54216 +12316 +-36320 +6205 +55352 +71630 +61423 +35576 +27676 +-7290 +73952 +67252 +60472 +46756 +43176 +124857 +81237 +13482 +15681 +26855 +90344 +42752 +64486 +58386 +80193 +5823 +42965 +29058 +44023 +15335 +40526 +52759 +63534 +11379 +14186 +29165 +-5593 +41506 +67255 +38671 +33926 +59047 +57643 +133258 +31542 +24377 +27867 +48249 +58072 +64481 +1575 +17983 +83291 +22481 +44068 +41123 +26400 +27283 +31880 +8264 +2883 +2620 +4201 +34848 +51199 +20470 +34984 +46669 +38739 +60054 +61270 +37059 +79620 +-4871 +47808 +51852 +22639 +-2661 +32209 +10269 +21671 +44447 +54275 +56781 +64073 +69465 +60396 +50127 +2077 +71988 +81653 +24549 +55252 +31575 +69984 +11105 +58077 +31304 +37552 +61890 +97787 +42272 +38115 +16657 +64399 +-1520 +9131 +33000 +33325 +95424 +64199 +28941 +98076 +74910 +27279 +-7177 +23718 +61120 +20009 +34104 +48181 +43513 +-24747 +25322 +-31250 +27822 +15957 +67352 +-9593 +26473 +100283 +29137 +24351 +6251 +25062 +18957 +38248 +6951 +42234 +54052 +-17437 +-33904 +47641 +12286 +78013 +37687 +58400 +-1374 +54503 +46338 +17288 +53230 +486 +78394 +127873 +82289 +10167 +95078 +42260 +55249 +46808 +45410 +-16126 +32788 +28384 +24131 +59051 +37314 +33313 +67005 +79122 +53128 +31603 +78265 +9591 +58998 +8250 +19901 +60016 +39667 +-48229 +53592 +72478 +-10315 +84537 +59935 +46142 +133819 +29406 +95380 +19592 +55575 +69200 +42167 +42040 +26086 +108261 +-13012 +7897 +-12719 +-3263 +38898 +18630 +49622 +-28938 +53955 +37477 +29384 +14420 +98948 +81951 +61535 +58485 +44686 +26691 +81238 +53884 +6530 +36330 +33326 +118469 +60044 +41527 +64916 +41138 +98669 +36356 +76617 +54644 +41816 +68261 +26222 +-20607 +30937 +-17384 +16010 +94973 +74272 +69583 +17574 +53768 +75832 +87276 +56541 +9343 +49924 +90831 +28802 +95081 +59652 +-846 +86172 +13267 +8345 +50634 +40776 +-6612 +104233 +29502 +31430 +92401 +-4825 +123329 +8435 +80227 +52901 +174633 +-12376 +-1784 +24111 +35422 +53118 +30384 +14127 +4252 +1905 +43320 +13633 +32675 +35474 +62550 +9492 +61724 +53586 +57490 +94823 +-192 +58331 +10350 +13036 +-9313 +22827 +61722 +33452 +25708 +95246 +12593 +44264 +17523 +-21595 +38841 +76353 +38050 +-8720 +66142 +33652 +58888 +55087 +59482 +34972 +56055 +34698 +89678 +34203 +61957 +42487 +35134 +114412 +24876 +27597 +25859 +-14144 +116170 +7362 +65799 +66825 +51588 +106242 +-11795 +84523 +88562 +10622 +87652 +2668 +59319 +12856 +-65273 +5699 +20373 +41976 +144260 +41191 +-939 +63034 +-11475 +-8104 +39925 +39870 +81099 +74770 +55308 +32149 +34452 +20416 +82976 +19949 +-8354 +44715 +5426 +84949 +41155 +5136 +14676 +25558 +5881 +28692 +35496 +-12888 +3855 +11207 +3677 +81314 +50219 +7996 +83291 +7701 +-31061 +44683 +63980 +79555 +68537 +54798 +4192 +34235 +26029 +93291 +36026 +28953 +55684 +77624 +3263 +15390 +28566 +84591 +91217 +16804 +99062 +804 +73136 +95065 +68013 +4994 +35331 +100000 +28989 +73433 +72101 +8976 +38024 +54719 +39657 +39235 +40541 +67626 +35178 +81238 +39272 +31913 +19418 +9131 +53715 +16274 +32611 +39733 +113 +37020 +11051 +77727 +67752 +59029 +30228 +87904 +11589 +57182 +71190 +76277 +-36829 +42809 +98348 +1606 +50356 +58335 +125075 +41879 +7889 +3220 +71874 +27029 +17900 +87600 +31874 +26040 +593 +66371 +60274 +123307 +50468 +17444 +36644 +47640 +52093 +68192 +-11749 +22351 +46657 +53998 +21320 +27140 +9988 +108767 +18267 +65241 +129 +79782 +23521 +32022 +60327 +6162 +47731 +-10829 +45003 +74654 +25891 +112012 +38036 +46255 +30360 +6797 +83972 +28403 +37603 +50750 +5295 +3355 +61253 +5411 +19855 +116350 +44794 +39736 +8919 +12933 +36932 +-29950 +49221 +72052 +15283 +70806 +43608 +49518 +12379 +17368 +22799 +25469 +65518 +29658 +1010 +23651 +37719 +27389 +30180 +47865 +20981 +50767 +42195 +98405 +22920 +36313 +98076 +-23934 +31942 +59241 +76892 +81871 +22164 +22139 +17048 +23449 +24947 +-12693 +23743 +37921 +67884 +33002 +67948 +34255 +24304 +63677 +4282 +7040 +36154 +19857 +-3987 +83314 +11799 +42680 +9573 +-19696 +-14051 +24258 +-8475 +30137 +98005 +46304 +28414 +6523 +71874 +7095 +68800 +14519 +34115 +31970 +23839 +30257 +63037 +93454 +23393 +73220 +99501 +23202 +78104 +36660 +5278 +1476 +88894 +55601 +40861 +30066 +34636 +-20347 +13416 +14405 +28438 +9079 +-31217 +39519 +31140 +77879 +12157 +35511 +76590 +39063 +28840 +59110 +-23582 +8196 +16509 +66125 +36164 +9309 +44559 +-3212 +69984 +-21415 +38093 +45547 +-4138 +72007 +59098 +693 +46614 +30746 +4744 +31361 +68437 +80791 +-2744 +61970 +10487 +-12135 +37871 +29038 +16652 +7386 +62262 +38400 +14708 +68423 +117840 +82172 +50390 +40514 +44305 +34840 +125953 +19791 +13764 +46250 +55925 +-37100 +46828 +38377 +-11985 +57277 +10123 +1773 +28618 +8588 +16419 +84190 +84518 +25975 +15978 +70830 +70351 +32368 +151715 +4085 +76015 +59633 +48906 +88482