From f4616b83993fb430270e768cce6849c3ed247f4a Mon Sep 17 00:00:00 2001 From: Damian Bregier Date: Tue, 18 May 2021 22:53:02 +0200 Subject: [PATCH] ADD: Basic linear regression model --- Main | 45 +++ out.tsv | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1045 insertions(+) create mode 100644 Main create mode 100644 out.tsv diff --git a/Main b/Main new file mode 100644 index 0000000..68b5fdd --- /dev/null +++ b/Main @@ -0,0 +1,45 @@ +#basic imports +import pandas +from sklearn.linear_model import LinearRegression + +#basic paths +openTrain = './train/train.tsv' +openDev = './dev-0/in.tsv' +openTest = './test-A/in.tsv' + +#read from files +with open('./names') as f_names: + names = f_names.read().rstrip('\n').split('\t') +read0 = pandas.read_table(openTrain, sep='\t', names=names) +read1 = pandas.read_table(openDev, sep='\t', names=['mileage', 'year', 'brand', 'engineType', 'engineCapacity']) + +#basic normalization & filtering +trainSet = pandas.get_dummies(read0, columns=['engineType']) +categories1 = trainSet.select_dtypes(include=object).columns.values +for c in categories1: + trainSet[c] = trainSet[c].astype('category').cat.codes +trainSet = trainSet.loc[(trainSet['price'] > 10000)] #to avoid suspicious observations +#for some reason this value gives the smallest RMSE according to geval, while smaller or bigger +#price gives RMSE >34k + +#Model training +X = trainSet.loc[:, trainSet.columns != 'price'] +solution = LinearRegression().fit(X, trainSet['price']) + +devSet = pandas.get_dummies(read1, columns=['engineType']) +categories2 = devSet.select_dtypes(include=object).columns.values +for c in categories2: + devSet[c] = devSet[c].astype('category').cat.codes + +predict = solution.predict(devSet) +predict.tofile("./dev-0/out.tsv", sep='\n') +testSet = pandas.get_dummies(read1, columns=['engineType']) + +categories3 = testSet.select_dtypes(include=object).columns.values +for c in categories3: + testSet[c] = testSet[c].astype('category').cat.codes + +predict = solution.predict(devSet) +predict.tofile("./test-A/out.tsv", sep='\n') + +#Outcome: 33956 for prices >10000 \ No newline at end of file diff --git a/out.tsv b/out.tsv new file mode 100644 index 0000000..a902880 --- /dev/null +++ b/out.tsv @@ -0,0 +1,1000 @@ +86806.20396842994 +7457.268670676276 +51041.757203830406 +11849.520249757916 +22190.328785087913 +83223.17021280341 +48481.833666091785 +4715.000321276486 +-14104.944025253877 +13225.799841344357 +24115.69919589348 +89930.35614182241 +720.6960084922612 +-3780.1865995265543 +36752.840259287506 +19016.801817437634 +66801.82012397423 +103958.69802160189 +39599.76849196665 +896.9522381052375 +-3195.218544535339 +5376.985123617575 +-23689.173811726272 +60567.40925037302 +-14618.354482552037 +76639.76555233821 +87215.74515330419 +8890.457275798544 +6232.185008328408 +37887.441058008 +79684.85944145545 +66615.96568952687 +1697.250009406358 +51256.398147735745 +39882.353340331465 +63279.85690055229 +34176.02000996843 +21162.65800321102 +43815.15421034768 +73779.28157807514 +82163.4572285898 +31870.002033578232 +39065.76394708268 +72829.31145203486 +8833.912841450423 +132442.7240405064 +99452.86686873063 +8978.228855965659 +37853.99113837443 +55262.47624893114 +79445.02139289305 +-18445.923827655613 +104952.39172318578 +42038.62218744308 +5305.540835469961 +-17564.80984867923 +-14137.293455006555 +26225.78457006067 +76200.46128266305 +19427.398317553103 +68789.11111477204 +-17901.70300446637 +-2154.8871350623667 +78794.05926639959 +89570.05513957329 +30727.740928905085 +-15497.792596014217 +94977.5431978181 +32333.277829669416 +-1597.5221789628267 +16724.84445554763 +33603.69815812074 +16730.629382375628 +13935.226420018822 +183893.31146616116 +39569.80019224249 +71089.29105546139 +43506.57308961265 +72368.09154085256 +10945.883433112875 +48459.52302822843 +19579.490251354873 +50734.29457353614 +12721.23072313331 +16282.18438433297 +21457.673451639712 +62107.1988396626 +40630.84143188037 +45205.564352234825 +22060.98716759868 +40106.36922663078 +34896.03193112649 +60708.57743499987 +46382.76691870205 +-4088.573324756697 +1297.4077349379659 +67337.87332008965 +68005.90409925766 +40267.4430347383 +28956.216169500723 +416.57705617137253 +-3552.2853391058743 +4075.6085083764046 +18341.922118702903 +3250.6445636190474 +25810.069868266582 +25087.85407495685 +45857.22185692936 +68563.25413798355 +15179.604650566354 +84018.54904660769 +-27288.78372546099 +57717.234051998705 +63342.51218468323 +4645.2944354806095 +41405.20434608683 +6478.847799509764 +35256.02541616 +59056.56064569019 +25997.998933482915 +21263.28317380324 +31773.004403535277 +-33452.625536922365 +29390.764925777912 +70410.31572473608 +82380.03098365478 +-32002.89705257304 +43577.14832603 +18152.32509751059 +49547.81018391438 +8266.199626080692 +-15495.13203686662 +45278.614929541945 +38467.348910816014 +-39268.312326529995 +67954.29741119221 +103931.69543468207 +59546.690942695364 +31068.642428046092 +67981.05226034299 +14850.570081871003 +55755.178901406005 +74103.13323032297 +15403.344421815127 +69815.69036308303 +53410.99236307107 +103784.1148788929 +10402.89920367673 +6390.927514405921 +60682.354195769876 +33482.81316853687 +14339.467941718176 +49333.07498294674 +-50206.796147599816 +79281.96738424897 +-24766.587097221985 +80269.9696921613 +18583.88220675476 +58897.42933030613 +64374.70224119723 +35907.55328600295 +73091.04315329716 +3175.5976487789303 +-10372.34955928661 +-4624.746437873691 +-21924.55961923115 +42318.53937416896 +39518.01429091208 +22404.245264828205 +91439.50905711204 +67497.15797271766 +78514.47942535393 +14878.172872776166 +17431.36770693399 +82577.7414513249 +38771.272209571674 +81469.58132718503 +106841.22894910723 +87182.43006461486 +82163.4572285898 +60026.72737249173 +32118.325641572475 +14026.69103096798 +-22512.37565167062 +18921.721440318972 +1193.6439885739237 +87747.81443761103 +37256.1189012602 +3104.0698529034853 +21106.37590924464 +-24305.888586040586 +44622.655143253505 +44430.342735964805 +67263.418974787 +-3683.1492099706084 +57761.08697916567 +39540.60997539386 +57954.38267719373 +19367.188931446522 +37271.66844375059 +112197.56162202917 +107579.93034999259 +-13206.58896101825 +-24596.09777016379 +18056.501486988738 +17583.485285719857 +35170.736064007506 +68262.5323068425 +74230.61067471467 +35376.01809219271 +24833.467792810872 +4178.191328918561 +96338.1965427231 +43938.77719408274 +37887.686426546425 +83458.01345830597 +52349.2117016837 +65883.3494345434 +129342.47449071892 +59664.05911414884 +-26006.79393758066 +32733.106214869767 +23692.44601281546 +-19749.02950265631 +39353.02302263118 +23999.32067171298 +-6802.899277571589 +42267.19004393183 +40011.79693360999 +56990.743956269696 +-778.6462150216103 +43888.65694013052 +24781.39406299591 +49417.976508993655 +-11523.063433064148 +-1569.3840525858104 +80126.18522785418 +50188.566184896976 +8874.265992835164 +67487.05740216188 +38801.577308859676 +22629.65521499701 +20394.10437503457 +52457.170668048784 +35286.04269369878 +10018.680152390152 +8798.712801184505 +46588.26021392085 +29405.720843419433 +6780.389949945733 +57433.22228336707 +24448.19026291184 +48830.601422669366 +79365.40541615337 +11602.70982580632 +95501.79653896764 +32933.96304335445 +91055.5206391029 +31997.78658793494 +18182.11215075478 +72831.59869383462 +3762.564174078405 +17020.80838261172 +11173.623521054164 +78969.41614289954 +22330.820974433795 +-10717.594643043354 +107474.09693599492 +-5072.117126818746 +14626.109840245917 +-21535.316010823473 +20440.02713395469 +14265.444357758388 +16261.336252717301 +76328.09289999865 +13291.017276462168 +14938.159366084263 +159466.7214099504 +20493.327222583815 +23390.53654408455 +133237.80625213683 +67322.5319961533 +8587.925364233553 +11932.174712371081 +82373.64771244116 +28486.254205040634 +89800.38516830467 +6036.642981346697 +34111.58525567129 +61482.06940040365 +25666.511845869943 +77528.61048456468 +39967.44012738019 +-5895.440222565085 +25928.718454349786 +36875.35857082158 +47121.0090667326 +29009.898051040247 +27746.52903809771 +56913.94840839319 +22599.992271024734 +6793.39596677199 +-4145.634469561279 +37002.501151982695 +11606.254951167852 +34633.30157769099 +4068.184124475345 +55289.65660055168 +39293.009471762925 +6688.555207636207 +-1559.768104718998 +-34872.51540484838 +25554.080295860767 +-28847.07311985083 +75725.95470191538 +96294.82058038563 +-2988.4432675447315 +24612.171823769808 +51484.771449662745 +24799.643556691706 +46234.65851637721 +55210.92152959667 +25070.152313791215 +10822.88888287358 +62062.958659676835 +84429.1002796758 +18407.560557736084 +44907.11431349628 +68591.20269607566 +32012.247692152858 +28627.602745724842 +69230.23744927719 +-1658.1501292549074 +33033.37150561437 +-17964.672842780128 +42912.44028804265 +45382.35061461851 +29664.709078356624 +54258.12503207661 +70190.43615080789 +140706.04705306888 +95443.01587695628 +46779.024567272514 +74263.35746422037 +7028.963357618079 +66776.84318111278 +10868.688313914463 +-2263.9360534157604 +57093.82716879621 +44008.83165094815 +60154.17394347116 +9999.457507811487 +49869.92564018257 +32186.45419997163 +55907.28351132572 +70397.75221613236 +3986.328356001526 +2427.801743749529 +58068.262105690315 +18874.019211232662 +107945.18264807202 +43985.56798287667 +-6344.5690451562405 +54327.766673510894 +49002.394638717175 +86224.44677147456 +194674.84981141426 +73724.6340537779 +57841.79604941048 +5250.120066681877 +31755.84489976801 +31882.3581067957 +-33332.32717840746 +78330.60345601104 +89864.56323194504 +45604.0307854861 +18881.874444663525 +51330.43818460964 +82847.16779231653 +38553.11234543845 +-29193.47250560485 +42297.5349544771 +34673.75388633832 +54667.17126378231 +-8871.434575852007 +27953.08134574257 +17584.883951026946 +-24634.016085950658 +23545.65124664828 +-4134.651945827529 +50427.48659147322 +75586.32474582456 +48796.227822361514 +23450.570869527757 +1492.7549563404173 +67591.33679792657 +22927.399114329368 +76702.9577840995 +34586.8492287267 +31728.98229171522 +53743.23359036073 +40839.345706790686 +94708.06821334362 +65855.55614328757 +54762.755082618445 +23100.500504996628 +-6911.358093850315 +19669.06021327339 +84305.11010440066 +88097.2258953061 +46964.23161130771 +2086.156585019082 +15319.456644155085 +261301.06916576624 +110587.50690004788 +135598.94817855954 +126042.51893338375 +5881.569328283891 +48139.539660649374 +52569.06624853052 +47549.334653371945 +73417.82856899686 +72593.58439815044 +86223.79061852209 +61288.707298444584 +50438.781556714326 +55050.12003529444 +-37464.502601129934 +58425.63463203795 +43479.65008373 +41153.97468557209 +82214.6992550902 +63233.69438371807 +25038.006312938407 +1169.7521060667932 +79740.11523036845 +16937.91476036422 +43207.47715845145 +27963.742779523134 +67513.26567322202 +31678.565960828215 +63045.93217527121 +19388.750154050067 +73513.2953022588 +67497.81412567012 +123598.76812034473 +43779.18306191452 +106979.39809214137 +71499.67333684303 +69580.7729964219 +66935.64983426407 +27569.53791972436 +-188.56994456984103 +14596.794900778681 +22777.504987159744 +52408.13229042478 +5841.254308259115 +68100.25101939961 +57083.221246363595 +34186.04703384265 +82273.62265299074 +10562.362035322934 +24281.474388936535 +20773.012123050168 +5664.54310339503 +38423.4283904247 +8022.355485500768 +93651.02018910274 +47262.265208646655 +39732.242014840245 +26127.246498830616 +14497.306771941483 +80922.12128833123 +76234.02119720355 +20864.708890412003 +56645.624169789255 +26420.63187579997 +20025.23941763118 +12718.463728744537 +66551.0441545099 +-42072.89326906577 +48503.009482402354 +20753.887664256617 +21391.524065913633 +13861.481415199116 +26715.842765707523 +58861.86598619819 +53030.934744937345 +32430.62687178701 +26544.880238741636 +48427.3774533011 +53653.98242254928 +86224.44677147456 +22117.925995141268 +14641.288693778217 +38540.00476114638 +66684.94855821691 +45273.15580837987 +84372.40994144976 +-5765.145574867725 +68136.42447369173 +28158.75753935799 +37484.51486892812 +26564.807273538783 +66163.25101084262 +66167.05743547156 +71267.26156219095 +919.746008977294 +97780.56076948904 +33530.22679234296 +-45495.90767083131 +116687.51822600327 +82578.27989224717 +15308.019850939512 +213302.62999051437 +53976.00647002831 +13204.612184455618 +51128.491110384464 +34321.572253601626 +-39643.23997734487 +17834.047207118943 +54529.766527310014 +115340.47648630105 +13158.46680062823 +22760.784597074613 +104009.74913452007 +-21718.71808380261 +102775.80956123397 +80159.2473145239 +73862.47248276323 +61460.14131170139 +27479.439917601645 +107895.49934797175 +11058.864695871249 +89052.82937225513 +5132.458196831867 +73373.35857686959 +-6554.521324250847 +67801.35977105424 +47690.37832314707 +82613.07565983012 +73575.28591291048 +29429.39773146808 +-8228.74269018136 +5513.935879772529 +-3210.7241749297827 +49450.20212088153 +14824.278409678489 +72237.94091230817 +74594.62325931899 +55220.81028128229 +59615.35576543026 +5859.255827821791 +28980.83129621297 +15016.063506411389 +-2922.887506665662 +11093.959979835898 +-20103.619593314826 +-2873.981592843309 +55847.372988073155 +146908.86666297168 +95242.26184119843 +-4031.3581855259836 +42039.36881184578 +40804.15318807773 +-39220.35793073103 +60102.05102000013 +13755.712980309501 +-11261.107550855726 +-4210.881848849356 +78412.52896167524 +37403.1995153185 +103039.90470533445 +70914.78112111054 +91007.87327448465 +58506.6672315225 +49817.00220473111 +99675.80420685932 +28912.873001838103 +68612.45553708822 +-14578.313405958936 +62424.61489757523 +-30323.84643524885 +63474.02370643988 +76723.4629850313 +8772.964126784354 +3161.7587165441364 +37570.83322614245 +71105.38715072908 +11472.641463629901 +-8671.704287080094 +22501.16178932786 +79553.49849533103 +11898.920316826552 +48438.76043189503 +69551.63437140547 +72950.96831339784 +139433.26835370623 +52950.75183240883 +-2217.8286405522376 +23792.59641848877 +75548.63639347814 +44466.44662309438 +64702.87972370908 +11827.164808187634 +33030.54925415851 +9447.673714721575 +-63687.03235263191 +22965.72108571045 +60246.50539538823 +48916.817394210026 +16278.890411432832 +-8264.983763400465 +58824.99471030384 +47522.23706554994 +43991.95126179792 +24606.23716835305 +18624.504104470834 +57247.96607694216 +43032.33453794196 +218889.07932393253 +14484.674594961107 +-28011.94196461141 +60844.0765982829 +39409.37686749734 +11151.13863350451 +39944.084457786754 +52801.67128781043 +6479.0253417845815 +78980.67417731695 +-9717.251612989232 +143601.5888609551 +97101.62180579826 +-7768.091375550255 +22755.451132541522 +-9067.292558437213 +27810.645436534658 +-9071.283159391955 +74818.10146163404 +23391.233185887337 +42155.97656108439 +-16042.814647085965 +18618.26817913167 +21975.789816970006 +35002.968046631664 +17492.850456237793 +50096.58598703332 +33012.99612832442 +65094.92374018021 +57830.48366861604 +54756.00679114461 +20809.390863824636 +23616.50560211949 +46622.747157732025 +66995.51052600332 +19523.361502602696 +60928.354408049956 +98664.02296228148 +97241.32632124051 +41771.860746178776 +54136.91862416454 +-6336.642577018589 +45741.276823354885 +25371.990058615804 +37114.984925899655 +39296.98893329874 +12479.253723477945 +9936.933063002303 +6490.956442866474 +96674.70344710164 +52588.42936198972 +32389.569167668 +-33.75364933721721 +96275.58500635996 +24528.83564335294 +30702.013188131154 +27454.9697021991 +85296.64647973329 +30204.0972940512 +46792.1329663638 +-50405.66904355772 +39058.845590643585 +12822.833039158955 +130277.50882166997 +78998.07305230945 +53471.56189242378 +69608.96851491928 +29153.584777969867 +34464.25713309087 +-17403.84181154892 +5201.366300892085 +5752.956833915785 +3666.3721137475222 +55021.07855206542 +47355.1960853748 +-2633.999103374779 +-30654.72022146918 +99853.00243492983 +-12254.301351521164 +72691.62357382104 +-7460.238060088828 +31550.165678273886 +104738.12903382257 +44706.333231735975 +19848.201234977692 +52793.567080590874 +64379.819389754906 +109159.55772452243 +34204.45387290418 +-30004.937242256477 +10950.388790382072 +-40538.26659848727 +18731.236831393093 +56413.31102636829 +1418.0499565135688 +34651.76625218429 +-20033.362133659422 +63380.0073062256 +134313.18092243 +51924.9075445272 +63257.75691756606 +-7477.528910215944 +40673.36934554763 +62065.25519501045 +-9795.616483341902 +-12044.673758951947 +59107.449178410694 +6765.353514513001 +21141.569738237187 +-7949.706489952281 +28116.931078065187 +87193.6297081504 +112536.78106686659 +8467.302067333832 +-4426.7770473416895 +92492.42993522808 +-7714.001139249653 +25901.299601027742 +15113.148614542559 +-508.56723632477224 +25841.012959051877 +15455.888512369245 +101599.50439372845 +65533.31899937242 +-6612.46898882091 +50175.643254544586 +56091.484127225354 +43826.02503777854 +60508.35546110384 +13944.243751067668 +63026.25972079672 +-42227.21764791012 +48554.73989811912 +80579.34580916539 +-4205.964810855687 +75725.46258720197 +46682.99115994573 +-22737.4582065437 +-57927.47306909785 +29062.793288020417 +7060.696135088801 +10309.62229949236 +25420.78033303283 +117776.9784287475 +28373.468618338928 +47267.26109838858 +25492.967434879392 +32674.078545590863 +-44829.83333436586 +45557.16912320629 +-38058.2158158496 +36812.27117744647 +31173.752911247313 +39275.8279034365 +56803.383537949994 +2985.2875649053603 +-38174.61898187362 +18264.802974360064 +43916.49309756979 +15609.144508363679 +19709.300021154806 +38256.03619991988 +-76672.1346270293 +65714.93636381812 +51562.22654373385 +796.4992912020534 +77881.21956679784 +63364.130084505305 +23833.329261904582 +10338.227015366778 +62708.110221976414 +792.8372324109077 +-14705.096614317968 +36296.92263679579 +189911.07368675992 +-25558.888382758945 +16105.338432978839 +88112.45679213665 +67497.15797271766 +15167.216417407617 +-22313.46917047724 +2025.9897330217063 +66068.50694778562 +10067.760972252116 +22377.011065447703 +-4529.399706766009 +27246.726199233904 +36337.39707253873 +58721.51781990379 +80471.87607386522 +-15452.115479888394 +65220.281119020656 +83199.65469285846 +-1432.744783975184 +40268.58980763517 +23014.45274886489 +13281.950715662912 +452.62709007784724 +83730.97196143493 +62065.25519501045 +37919.47484655306 +28061.218411888927 +-1087.3913675025105 +35538.74110384472 +25438.02380493842 +74818.10146163404 +47089.44148893654 +-17399.69844486378 +62062.958659676835 +102026.08254858106 +21632.923580801114 +51054.50538276322 +55758.07937815599 +81004.3655721154 +-2226.336093487218 +47706.616045143455 +64041.76723470166 +10938.812071653083 +-17264.85603508167 +49992.68290161155 +20774.950246222317 +41103.0765658021 +69153.20954490639 +40272.80831669271 +-2798.7224709447473 +38782.577237814665 +29699.601294670254 +71908.74097749777 +17873.60417948477 +21432.83818835765 +26946.028242260218 +31271.25329533033 +28201.459874961525 +62487.68816262297 +67825.51695918106 +59767.17990960367 +6119.257560189813 +53457.015712834895 +19962.906794188544 +-15280.569789372385 +17181.8015764039 +10505.270568573847 +-16835.708031354472 +44762.3813981507 +19876.5499801673 +-24376.689126892015 +16272.132565388456 +19835.61457164772 +29038.583293041214 +10260.747073058039 +77722.41792361625 +54460.52968871221 +37076.663364399225 +38374.50540876947 +4702.957717243582 +109160.21387747489 +44416.74309424125 +140743.45363375172 +68416.67783239856 +80171.58534090593 +33536.84447135404 +24270.03759572096 +66864.39327904955 +14352.96560765244 +41787.127908010036 +87081.44647043571 +45667.58242260665 +54648.4695401676 +103169.31200878508 +3445.4314556140453 +-5784.541359553114 +26202.113014264032 +-7751.572367813438 +22716.339680865407 +40870.62092966214 +-73137.7417252101 +37354.822731023654 +-26264.038029696792 +60803.34943052754 +87125.68945058808 +55597.69494453259 +26741.11510605924 +86224.44677147456 +-8565.298454327509 +26907.681362353265 +43572.36110284552 +-26617.09745603986 +16975.37272350304 +43383.06281692907 +93465.51485547423 +63851.870370807126 +129842.69165988825 +106016.69475596957 +64581.165232833475 +20677.649519896135 +-24714.839008660987 +28375.390568817034 +14744.70135015808 +24903.451641604304 +28396.360115928575 +98580.36116509512 +86329.7880707588 +-3222.3937817253172 +28032.499251633883 +79487.24337768182 +84755.81336823292 +106216.48731458187 +34815.02435447276 +10474.587149117142 +11844.07688499242 +64375.139442842454 +45906.23801157437 +28134.483445404097 +61819.12325981818 +13473.31251271069 +38713.39194067754 +71751.41698018461 +89126.17060519941 +65512.84135013819 +61878.067409629 +-16808.162405615672 +-26409.84038713202 +29563.08491334319 +98318.25111339986 +43056.6240697857 +77253.73976101726 +68490.66409325413 +-23479.572361128405 +-290.26299242675304 +97000.52969100885 +27186.180927094072 +37311.5559579432 +1182.3485789895058 +-13065.84326087311 +33859.9672485888 +69400.06270493008 +74099.23654799536 +18166.568599430844 +16053.503178877756 +17907.516403440386 +949.69320211187 +64861.6461523734 +40053.718047646806 +92547.54230096936 +74978.20735529996 +15749.55952545628 +19379.552753932774 +77146.84314939752 +81072.09754344821 +-1411.5615056417882 +59876.27880187519 +80593.23113734834 +50050.4090122059 +43899.249625664204 +52464.4592480734 +35150.91268291511 +-8024.805412124842 +82163.4572285898 +21607.517445040867 +-2008.0950187128037 +41992.856966974214 +78628.51529559493 +80391.75930166431 +-2373.7323328945786 +-1111.858579268679 +12181.584980746731 +72620.10709595494 +84749.92397824861 +73147.20650910959 +38710.10138228536 +36013.580835107714 +2012.8196410443634 +47258.99773722328 +47094.469041612 +-40277.02587039769 +15147.43570613116 +76476.16858083569 +81402.71410673298 +43028.26821292937 +130997.30267402902 \ No newline at end of file