Commit 3d8f6d62 authored by Thomas Torsney-Weir's avatar Thomas Torsney-Weir

code for assignment

parents
__pycache__
.hypothesis
**Please note**: You cannot use any external packages or native libraries
*except* where specifically mentioned. Be careful with when importing
packages!
## Part 1 - Python (30 points)
The first part of this assignment is intended to get you up and running with
Python. We have provided a repository on [gitlab](). Please use the file
`l1p1.py` in this file to write your code.
In the repository we have also provided some test cases which you can use
to test your code. You'll need to install some packages first though. So set
up a virtual environment for yourself and run `pip install -r requirements.txt`
to install the pacakges you'll need. Then you can run one of the tests like
so:
```
./test_assignment.sh
```
### Question 1 (10 points)
Write a function to sort a list of integers. You can write any algorithm you
want including, quicksort, merge sort, bubble sort, or random sort. However,
you need to write the code yourself. Python and numpy both provide library
methods for sorting lists but you cannot use them.
Here are some examples:
```
>>> sort_list([1,2,3])
[1,2,3]
>>> sort_list([5,4,3,2])
[2,3,4,5]
```
### Question 2 (10 points)
This question is inspired by one of the divisibility tricks in a recent
[numberphile video](https://www.youtube.com/watch?v=yi-s-TTpLxY&t=178s).
This time we're going to play around with number theory. The task here is to
write a function that, given an integer and a single integer digit, returns
an integer that inserts the digit in the integer such that the new integer is
divisible by 7. The digits of the original integer must remain in the same
order. If this is not possible then the function should throw an exception
with message "not possible"
Examples:
```
>>> div7(123, 4)
4123
>>> div7(39, 2)
```
Examples of incorrect output:
```
# not divisible by 7
>>> div7(123,4)
1234
# cannot reorder digits in first argument
>>> div7(124, 3)
4123
```
### Question 3 (10 points)
Note the import of numpy within the function. Don't alter this line, you can
only use numpy in this particular function. Here the task is to extend the
cubic function $y = a_1 x^3 + a_2 x^2 + a_3 x + a_4$ to handle multi-variate
arguments. In other words, rather than having a scalar $x$ and a vector of
coefficients, $a$. You will now have a vector of inputs for $x$ and a matrix
of coefficients, $a$. Each column of $a$ is the coefficients for the $i$th
element of the vector $x$. This function should still return a scalar value.
Examples:
```
>>> cubic(np.array([1,2,3,4]), np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]))
???
```
## Part 2 - Regression analysis (70 points)
For this part we’re going to explore which factors contribute to the happiness
score (the column called "happiness_score") for various countries (csv file).
The idea is to predict the happiness score based on 13 factors. For these parts
submit a single file of your python code called l1p2.ipynb. Please clearly
comment the file so we can understand which parts of the code are associated
with which project. For the writeup, also submit a pdf called l1p2.pdf. The
Jupyter notebook file should produce this pdf. See below for directions on how
to do this. It is your responsibility to ensure that this can be run on the
grader's computer. We will use a python distribution set up with scikit-learn,
numpy, pandas, and matplotlib.
### Q2.1 (20 points)
First we want to get an overview of the data. Write a report that contains the
following parts:
1. Use matplotlib to make a scatterplot of each variable against the
happiness score.
2. Explain the trends you see in each of the plots. Explain if you see any
trend and what kind of trend you see (linear, quadratic, logrithmic, etc).
(one sentence for each plot should be sufficient)
3. before doing the later parts of the assignment, explain which factors you
think are important for predicting the happiness index and why. (one paragraph)
### Q2.2 (50 points)
Now it’s time to build a model of the data. For this you should use the
[KernelRidge](http://scikit-learn.org/stable/modules/generated/sklearn.kernel_ridge.KernelRidge.html#sklearn.kernel_ridge.KernelRidge)
module from scipy.
For the evaulation report both the $R^2$ value as well as the 5-fold cross
validation results for each model.
1. Check for any missing values in the dataset. Any missing values will cause
an error when you try to build a model.
2. Come up with a way (and modify the dataset programmatically). **DO NOT
change the CSV file itself**. It's important to document your work use code
as much as possible so that your results are reproducable. We will diff the
csv file submitted against our copy and it cannot differ.
3. Build a linear model and evaluate it (HINT: linear kernel)
4. Build a polynomial model and evaluate it (HINT: polynomial kernel)
5. Build a Gaussian model and evaluate it (HINT: Gaussian/RBF kernel)
6. Compare the 3 different models:
* which degree of polynomial provided the best fit?
* which values of gamma and alpha for the fitting procedure gave the
best fit?
* write which model is the best fit to the data and why
(1 paragraph will be sufficient)
### Converting a Jupyter notebook to pdf
Jupyter comes with a function called [nbconvert]() that can convert Juyter
notebooks to a variety of formats. To convert your notebook to pdf you'll also
need LaTeX and [pandoc](https://pandoc.org/) installed. Once you've done this
you can convert the notebook from the command line:
```
>>> jupyter nbconvert --to pdf l1p2.ipynb
```
### Procedure and Submission
Please submit a ZIP-document with your answers to [Moodle](). Use the following
naming scheme for your submission: “lastname_matrikelnumber_A1.zip”. The naming
of the files is important. If you do not follow the submission instructions,
then you will receive a grade of 0 for the lab.
### Late submission
Late Submissions are NOT possible. Any assignment submitted late will receive zero points.
[Academic Honesty](http://vda.univie.ac.at/Teaching/FDA/19s/academicHonesty.html)
country,happiness_rank,happiness_score,economy,family,health,freedom,generosity,corruption,dystopia_residual,internet_access_population[%],cellular_subscriptions,surplus_deficit_GDP[%],familiy_income_gini_coeff,GDP_per_capita[$],inflation_rate[%],military_expenditures[%],map_reference,biggest_official_language,population
Norway,1,7.537000179290769,1.6164631843566901,1.53352355957031,0.796666502952576,0.635422587394714,0.36201223731041,0.31596383452415505,2.27702665328979,97.3,108,4.2,26.8,71800,1.9,1.62,Europe,Bokmal Norwegian,5320045
Denmark,2,7.52199983596802,1.48238301277161,1.55112159252167,0.7925655245780941,0.626006722450256,0.3552804887294771,0.40077006816863997,2.31370735168457,97,124,-0.6000000000000001,29,49900,1.1,1.15,Europe,Danish,5605948
Iceland,3,7.50400018692017,1.480633020401,1.6105740070343,0.8335521221160892,0.6271626353263849,0.47554022073745705,0.15352655947208402,2.32271528244019,98.2,121,0.9,28,51800,1.8,0.1,Arctic Region,Icelandic,339747
Switzerland,4,7.49399995803833,1.5649795532226598,1.51691174507141,0.858131289482117,0.620070576667786,0.29054927825927696,0.36700728535652205,2.2767162322998,89.4,137,0.2,29.5,61400,0.5,0.71,Europe,German,8236303
Finland,5,7.468999862670901,1.44357192516327,1.5402467250824,0.80915766954422,0.6179508566856379,0.24548277258873,0.38261154294014,2.4301815032958998,87.7,132,-2,27.2,44300,0.8,1.23,Europe,Finnish,5518371
Netherlands,6,7.3769998550415,1.50394463539124,1.42893922328949,0.8106961250305179,0.5853844881057739,0.47048982977867104,0.282661825418472,2.29480409622192,90.4,120,0.30000000000000004,30.3,53600,1.3,1.17,Europe,Dutch,17084719
Canada,7,7.31599998474121,1.47920441627502,1.48134899139404,0.83455765247345,0.611100912094116,0.435539722442627,0.287371516227722,2.18726444244385,89.8,88,-2,32.1,48300,1.6,0.99,North America,English,35623680
New Zealand,8,7.31400012969971,1.40570604801178,1.54819512367249,0.816759705543518,0.6140621304512021,0.500005125999451,0.38281670212745705,2.0464563369751,88.5,142,0.7000000000000001,36.2,38900,1.9,1.1,Oceania,English,4510327
Sweden,9,7.28399991989136,1.49438726902008,1.47816216945648,0.830875158309937,0.612924098968506,0.38539925217628496,0.384398728609085,2.09753799438477,91.5,125,0.9,24.9,51500,1.9,1.1,Europe,Swedish,9960487
Australia,10,7.28399991989136,1.4844149351120002,1.5100419521331798,0.84388679265976,0.601607382297516,0.47769924998283403,0.301183730363846,2.06521081924438,88.2,119,-1.7000000000000002,30.3,50300,2,2,Oceania,English,23232413
Israel,11,7.212999820709231,1.3753824234008798,1.37628996372223,0.83840399980545,0.40598860383033797,0.330082654953003,0.0852421000599861,2.80175733566284,79.8,127,-2.7,42.8,36300,0.2,5.62,Middle East,Hebrew,8299706
Costa Rica,12,7.0789999961853,1.10970628261566,1.4164036512374898,0.7595092654228209,0.580131649971008,0.21461322903633104,0.100106589496136,2.89863920211792,66,179,-5.2,48.5,16900,1.6,,Central America and the Caribbean,Spanish,4930258
Austria,13,7.00600004196167,1.4870972633361799,1.4599449634552,0.8153284192085269,0.567766189575195,0.316472321748734,0.22106036543846105,2.1385064125061004,84.3,170,-1.2,30.5,49900,2.2,0.58,Europe,German,8754413
United States,14,6.993000030517581,1.54625928401947,1.4199205636978103,0.7742866277694699,0.505740523338318,0.392578780651093,0.135638788342476,2.2181134223937997,76.2,121,-3.4,45,59500,2.1,3.29,North America,English,326625791
Ireland,15,6.9770002365112305,1.5357066392898602,1.5582311153411899,0.8097826242446899,0.5731103420257571,0.42785832285881,0.29838815331459007,1.77386903762817,82.2,98,-0.6000000000000001,31.3,75500,0.30000000000000004,0.34,Europe,English,5011102
Germany,16,6.9510002136230495,1.48792338371277,1.47252035140991,0.798950731754303,0.562511384487152,0.33626917004585305,0.276731938123703,2.01576995849609,89.6,132,0.7000000000000001,27,50400,1.7000000000000002,1.2,Europe,German,80594017
Belgium,17,6.89099979400635,1.4637807607650801,1.4623126983642598,0.8180918693542479,0.5397707223892211,0.23150333762168898,0.251343131065369,2.12421035766602,86.5,104,-1.5,25.9,46600,2.2,0.9,Europe,Dutch,11491346
Luxembourg,18,6.86299991607666,1.74194359779358,1.45758366584778,0.845089495182037,0.59662789106369,0.283180981874466,0.31883442401886,1.61951208114624,97.5,134,0.5,30.4,106300,2.1,0.54,Europe,Luxembourgish,594130
United Kingdom,19,6.71400022506714,1.44163393974304,1.4964600801467902,0.805335938930511,0.508190035820007,0.492774158716202,0.265428066253662,1.7041435241699199,94.8,121,-3.6,32.4,44100,2.7,2.2,Europe,English,65648100
Chile,20,6.65199995040894,1.25278460979462,1.28402495384216,0.8194797039031979,0.376895278692245,0.3266624212265011,0.0822879821062088,2.5095858573913596,66,129,-3.1,50.5,24500,2.2,1.87,South America,Spanish,17789267
United Arab Emirates,21,6.6479997634887695,1.6263433694839498,1.2664102315902699,0.726798236370087,0.60834527015686,0.3609419465065,0.324489563703537,1.734703540802,90.6,326,-7.6,,67700,2,4.86,Middle East,Arabic,6072475
Brazil,22,6.6350002288818395,1.1073532104492199,1.43130600452423,0.6165523529052729,0.437453746795654,0.16234989464282998,0.11109276115894301,2.7692670822143595,59.7,114,-1.3,49,15600,3.4,1.32,South America,Portuguese,207353391
Czech Republic,23,6.60900020599365,1.35268235206604,1.4338852167129499,0.754444003105164,0.49094617366790794,0.0881067588925362,0.0368729270994663,2.45186185836792,76.5,118,0.4,25,35500,2.4,0.98,Europe,Czech,10674723
Argentina,24,6.59899997711182,1.18529546260834,1.44045114517212,0.695137083530426,0.49451920390129106,0.109457060694695,0.05973988771438599,2.61400532722473,70.2,140,-6.1,41.7,20900,25.7,0.9500000000000001,South America,Spanish,44293293
Mexico,25,6.57800006866455,1.1531838178634601,1.2108621597290001,0.709978997707367,0.412730008363724,0.12099043279886199,0.132774114608765,2.8371548652648904,59.5,92,-1.9,48.2,19900,6,0.58,North America,Spanish,124574795
Singapore,26,6.57200002670288,1.69227766990662,1.35381436347961,0.9494923949241642,0.549840569496155,0.345965981483459,0.46430778503417997,1.2163619995117199,81,144,1.8,45.9,93900,0.6000000000000001,3.35,Southeast Asia,English,5888926
Malta,27,6.52699995040894,1.34327983856201,1.48841166496277,0.821944236755371,0.588767051696777,0.5747305750846861,0.153066068887711,1.55686283111572,77.3,135,-0.5,28.1,42000,1.3,0.53,Europe,Maltese,416338
Uruguay,28,6.4539999961853,1.2175596952438401,1.4122278690338101,0.719216823577881,0.5793922543525699,0.175096929073334,0.17806187272071802,2.17240953445435,66.4,152,-3.7,41.6,22400,6.2,1.85,South America,Spanish,3360148
Guatemala,29,6.4539999961853,0.872001945972443,1.25558519363403,0.540239989757538,0.5313106179237371,0.283488392829895,0.0772232785820961,2.89389109611511,34.5,129,-3.2,53,8100,4.4,0.39,Central America and the Caribbean,Spanish,15460732
Panama,30,6.4520001411438,1.23374843597412,1.3731925487518302,0.706156134605408,0.550026834011078,0.21055693924427,0.070983923971653,2.30719995498657,54,159,-1.6,50.7,25400,0.9,,Central America and the Caribbean,Spanish,3753142
France,31,6.44199991226196,1.43092346191406,1.38777685165405,0.8444658517837521,0.470222115516663,0.129762306809425,0.172502428293228,2.00595474243164,85.6,103,-2.7,29.3,43800,1.2,2.26,Europe,French,67106161
Thailand,32,6.4239997863769505,1.12786877155304,1.4257924556732198,0.647239029407501,0.580200731754303,0.572123110294342,0.0316127352416515,2.03950834274292,47.5,178,-2.5,44.5,17900,0.7000000000000001,1.5,Southeast Asia,Thai,68414135
Taiwan,33,6.42199993133545,1.4336265325546298,1.38456535339355,0.793984234333038,0.361466586589813,0.258360475301743,0.0638292357325554,2.1266074180603,88,122,0.2,33.6,50300,0.6000000000000001,,Southeast Asia,Mandarin Chinese,23508428
Spain,34,6.40299987792969,1.38439786434174,1.53209090232849,0.888960599899292,0.408781230449677,0.190133571624756,0.0709140971302986,1.92775774002075,80.6,107,-3.3,35.9,38300,2,0.91,Europe,Castilian Spanish,48958159
Qatar,35,6.375,1.8707656860351598,1.27429687976837,0.7100980877876278,0.604130983352661,0.33047387003898604,0.43929925560951205,1.1454644203186002,94.3,169,-6.2,,124500,0.4,,Middle East,Arabic,2314307
Colombia,36,6.35699987411499,1.07062232494354,1.4021829366683998,0.595027923583984,0.47748741507530196,0.14901447296142598,0.0466687418520451,2.6160681247711204,58.1,130,-3.4,51.1,14500,4.3,3.5,South America,Spanish,47698524
Saudi Arabia,37,6.343999862670901,1.53062355518341,1.28667759895325,0.590148329734802,0.449750572443008,0.147616013884544,0.27343225479126004,2.0654296875,73.8,141,-8.8,45.9,54800,-0.9,9.85,Middle East,Arabic,28571770
Trinidad and Tobago,38,6.1680002212524405,1.36135590076447,1.3802285194397,0.5199832916259771,0.518630743026733,0.32529646158218395,0.00896481610834599,2.0532474517822297,69.2,167,-4.5,,31400,1.9,1.12,Central America and the Caribbean,English,1218208
Kuwait,39,6.10500001907349,1.63295245170593,1.25969874858856,0.6321057081222529,0.49633759260177596,0.228289797902107,0.21515955030918102,1.64042520523071,78.4,179,-7.2,,66200,1.5,4.83,Middle East,Arabic,2875422
Slovakia,40,6.09800004959106,1.32539355754852,1.5050592422485398,0.712732911109924,0.295817464590073,0.136544480919838,0.0242108516395092,2.09777665138245,80.5,131,-1.5,23.7,33000,1.3,1.16,Europe,Slovak,5445829
Bahrain,41,6.08699989318848,1.4884122610092199,1.3231104612350502,0.653133034706116,0.536746919155121,0.17266848683357197,0.257042169570923,1.65614938735962,98,168,-10.3,,48500,1.4,4.59,Middle East,Arabic,1410942
Malaysia,42,6.08400011062622,1.29121541976929,1.28464603424072,0.618784427642822,0.40226498246192893,0.416608929634094,0.0656007081270218,2.00444889068604,78.8,135,-2.9,46.2,29000,3.8,1.4100000000000001,Southeast Asia,Bahasa Malaysia,31381992
Nicaragua,43,6.07100009918213,0.737299203872681,1.28721570968628,0.6530959606170649,0.447551846504211,0.301674216985703,0.130687981843948,2.51393055915833,24.6,136,-2,47.1,5800,3.9,0.55,Central America and the Caribbean,Spanish,6025951
Ecuador,44,6.00799989700317,1.00082039833069,1.2861688137054401,0.685636222362518,0.4551981985569,0.15011246502399403,0.140134647488594,2.29035258293152,54.1,85,-5.5,45.9,11500,0.4,1.7000000000000002,South America,Spanish,16290913
El Salvador,45,6.002999782562259,0.9097844958305359,1.1821250915527302,0.596018552780151,0.432452529668808,0.0782579854130745,0.0899809598922729,2.7145938873291002,29,162,-3.6,36,8900,1,0.87,Central America and the Caribbean,Spanish,6172011
Poland,46,5.97300004959106,1.29178786277771,1.44571197032928,0.699475347995758,0.520342111587524,0.158465966582298,0.0593078061938286,1.7977228164672898,73.3,130,-2.3,30.8,29500,2,1.99,Europe,Polish,38476269
Uzbekistan,47,5.97100019454956,0.786441087722778,1.5489691495895401,0.498272627592087,0.6582486629486078,0.41598364710807795,0.246528223156929,1.8169136047363301,46.8,82,0.30000000000000004,36.8,6900,12.5,,Asia,Uzbek,29748859
Italy,48,5.96400022506714,1.3950666189193701,1.44492328166962,0.8531443476676941,0.256450712680817,0.17278964817523998,0.0280280914157629,1.81331205368042,61.3,135,-2.3,31.9,38100,1.3,1.12,Europe,Italian,62137802
Russia,49,5.962999820709231,1.28177809715271,1.46928238868713,0.547349333763123,0.373783111572266,0.0522638224065304,0.0329628810286522,2.20560741424561,76.4,160,-2.3,41.2,27800,3.7,5.4,Asia,Russian,142257519
Belize,50,5.955999851226809,0.907975316047668,1.0814177989959701,0.45019176602363603,0.5475093722343439,0.24001564085483604,0.0965810716152191,2.63195562362671,44.6,63,-2.7,,8300,1.1,1.17,Central America and the Caribbean,English,360346
Japan,51,5.92000007629395,1.41691517829895,1.43633782863617,0.9134758710861209,0.505625545978546,0.12057276815175999,0.163760736584663,1.36322355270386,92,135,-4.6,37.9,42800,0.5,0.93,Asia,Japanese,126451398
Lithuania,52,5.90199995040894,1.3145823478698702,1.47351610660553,0.62894994020462,0.234231784939766,0.010164656676352,0.0118656428530812,2.22844052314758,74.4,154,0,37.9,32300,3.7,2,Europe,Lithuanian,2823859
Algeria,53,5.872000217437741,1.09186446666718,1.1462174654007,0.6175846457481379,0.233335807919502,0.0694366469979286,0.14609611034393302,2.5676038265228303,42.9,122,-10.6,35.3,15200,5.6,6.55,Africa,Arabic,40969443
Latvia,54,5.849999904632571,1.26074862480164,1.40471494197845,0.638566970825195,0.32570791244506797,0.153074786067009,0.0738427266478539,1.9936552047729499,79.9,127,-0.5,34.5,27600,2.9,1.7000000000000002,Europe,Latvian,1944643
South Korea,55,5.837999820709231,1.40167844295502,1.1282744407653797,0.900214076042175,0.257921665906906,0.206674367189407,0.0632826685905457,1.8803780078887902,89.9,124,1,35.7,39400,1.9,2.7,Asia,Korean,51181299
Moldova,56,5.837999820709231,0.7288706302642819,1.25182557106018,0.5894652009010309,0.24072904884815197,0.20877912640571603,0.0100912861526012,2.80780839920044,71,105,-0.8,26.8,5700,6.6,0.37,Europe,Moldovan/Romanian,3474121
Romania,57,5.824999809265139,1.21768391132355,1.15009129047394,0.6851583123207089,0.457003742456436,0.133519917726517,0.0043879006989300294,2.17683148384094,59.5,105,-3.1,27.3,24500,1.3,1.42,Europe,Romanian,21529967
Bolivia,58,5.82299995422363,0.833756566047668,1.2276190519332901,0.47363024950027505,0.5587329268455511,0.22556072473526,0.0604777261614799,2.4432790279388397,39.7,91,-6.2,47,7500,2.8,1.5,South America,Spanish,11138234
Turkmenistan,59,5.82200002670288,1.1307767629623402,1.49314916133881,0.437726080417633,0.41827192902565,0.24992498755454998,0.25927034020423895,1.83290982246399,18,160,-0.6000000000000001,40.8,18100,8,,Asia,Turkmen,5351277
Kazakhstan,60,5.8189997673034695,1.2845562696456898,1.3843690156936599,0.6060415506362921,0.43745428323745705,0.20196442306041698,0.11928288638591802,1.7848925590515101,76.8,143,-2.3,26.3,26300,7.4,0.8200000000000001,Asia,Kazakh,18556698
Northern Cyprus,61,5.80999994277954,1.3469113111496,1.18630337715149,0.834647238254547,0.47120362520217896,0.266845703125,0.155353352427483,1.5491576194763201,75.9,96,-0.9,34.8,37000,0.7000000000000001,1.78,Middle East,Greek,1221549
Slovenia,62,5.75799989700317,1.3412059545516999,1.4525188207626298,0.7908282279968258,0.572575807571411,0.242649093270302,0.0451289787888527,1.31331729888916,75.5,124,-0.7000000000000001,24.4,34400,1.4,0.92,Europe,Slovenian,1972126
Peru,63,5.71500015258789,1.0352252721786501,1.21877038478851,0.6301661133766171,0.45000287890434293,0.126819714903831,0.0470490865409374,2.2072694301605202,45.5,125,-2.8,45.3,13300,2.8,0.9,South America,Spanish,31036656
Mauritius,64,5.62900018692017,1.1893955469131499,1.20956099033356,0.6380074620246889,0.491247326135635,0.360933750867844,0.0421815551817417,1.6975839138031,53.2,136,-3.5,35.9,21600,3.7,0.19,Africa,Creole,1356388
Cyprus,65,5.62099981307983,1.3559380769729599,1.13136327266693,0.84471470117569,0.35511153936386103,0.271254301071167,0.0412379764020443,1.62124919891357,75.9,96,-0.9,34.8,37000,0.7000000000000001,1.78,Middle East,Greek,1221549
Estonia,66,5.61100006103516,1.3208793401718102,1.47667109966278,0.695168316364288,0.479131430387497,0.0988908112049103,0.18324892222881303,1.35750865936279,87.2,152,-0.2,34.8,31800,3.7,2.17,Europe,Estonian,1251581
Belarus,67,5.5689997673034695,1.15655755996704,1.4449452161788898,0.6377142667770389,0.295400261878967,0.15513750910759,0.156313821673393,1.72323298454285,71.1,115,0.5,26.5,18900,6,0.93,Europe,Russian,9549747
Libya,68,5.525000095367429,1.1018030643463101,1.3575643301010099,0.520169019699097,0.465733230113983,0.15207366645336198,0.0926102101802826,1.8350112438201898,20.3,115,-18,,10000,28,,Africa,Arabic,6653210
Turkey,69,5.5,1.1982743740081798,1.33775317668915,0.6376056075096129,0.300740599632263,0.0466930419206619,0.0996715798974037,1.87927794456482,58.3,96,-2,40.2,26900,11.1,1.73,Middle East,Turkish,80845215
Paraguay,70,5.493000030517581,0.932537317276001,1.50728487968445,0.579250693321228,0.473507791757584,0.224150657653809,0.091065913438797,1.6853334903716999,51.3,108,-1.8,51.7,9800,3.6,1.25,South America,Spanish,6943739
"Hong Kong S.A.R., China",71,5.47200012207031,1.55167484283447,1.26279091835022,0.943062424659729,0.490968644618988,0.374465793371201,0.29393374919891396,0.554633140563965,85,255,5.2,53.9,61400,1.5,,Southeast Asia,Cantonese,7191503
Philippines,72,5.42999982833862,0.85769921541214,1.25391757488251,0.46800905466079706,0.585214674472809,0.193513423204422,0.0993318930268288,1.9726047515869098,55.5,111,-2.2,44.4,8300,3.2,1.28,Southeast Asia,Filipino and English ; eight major dialects - Tagalog,104256076
Serbia,73,5.39499998092651,1.06931757926941,1.2581897974014298,0.65078467130661,0.20871552824974102,0.22012588381767298,0.0409037806093693,1.94708442687988,67.1,121,-1.7000000000000002,38.7,15000,3.1,1.34,Europe,Serbian,7111024
Jordan,74,5.33599996566772,0.9910123944282528,1.2390888929367099,0.6045900583267211,0.418421149253845,0.17217046022415197,0.11980327218771002,1.79117655754089,62.3,96,-6.6,39.7,12500,3.3,4.8,Middle East,Arabic,10248069
Hungary,75,5.32399988174438,1.2860119342803997,1.34313309192657,0.6877634525299069,0.17586351931095098,0.0784016624093056,0.0366369374096394,1.7164592742919902,79.3,122,-2.1,28.2,29500,2.4,1.01,Europe,Hungarian,9850845
Jamaica,76,5.31099987030029,0.925579309463501,1.3682180643081698,0.6410223841667181,0.474307239055634,0.23381833732128102,0.0552677810192108,1.61232566833496,45,103,1.3,35,9200,4.4,0.8200000000000001,Central America and the Caribbean,English,2990561
Croatia,77,5.2930002212524405,1.22255623340607,0.9679830074310299,0.701288521289825,0.255772292613983,0.248002976179123,0.0431031100451946,1.85449242591858,72.7,101,-0.5,30.8,24400,1.1,1.27,Europe,Croatian,4292095
Kosovo,78,5.27899980545044,0.951484382152557,1.1378535032272301,0.541452050209045,0.260287940502167,0.319931447505951,0.0574716180562973,2.0105407238006596,,31,-2.2,23.2,10500,1.5,0.79,Europe,Albanian,1895250
China,79,5.2729997634887695,1.08116579055786,1.16083741188049,0.741415500640869,0.47278770804405196,0.0288068410009146,0.0227942746132612,1.76493859291077,53.2,107,-4.3,46.5,16700,1.6,1.9,Asia,Standard Chinese or Mandarin,1379302771
Pakistan,80,5.26900005340576,0.7268835306167599,0.6726906895637509,0.40204778313636796,0.23521526157856,0.31544601917266807,0.12434806674718901,2.7924892902374303,15.5,71,-4.9,30.7,5400,4.1,3.56,Asia,Punjabi,204924861
Indonesia,81,5.26200008392334,0.995538592338562,1.2744446992874099,0.49234572052955605,0.443323463201523,0.611704587936401,0.0153171354904771,1.42947697639465,25.4,176,-4.3,36.8,12400,3.8,0.84,Southeast Asia,Bahasa Indonesia,260580739
Venezuela,82,5.25,1.12843120098114,1.43133759498596,0.617144227027893,0.15399712324142498,0.0650196298956871,0.0644911229610443,1.78946375846863,60,78,-38.1,39,12100,1087.5,1,South America,Spanish,31304016
Montenegro,83,5.23699998855591,1.12112903594971,1.23837649822235,0.6674646735191351,0.194989055395126,0.197911024093628,0.0881741940975189,1.72919154167175,69.9,163,-6.1,31.9,17700,2.4,1.7000000000000002,Europe,Serbian,642550
Morocco,84,5.2350001335144,0.8781145811080929,0.774864435195923,0.59771066904068,0.408158332109451,0.0322099551558495,0.0877631828188896,2.45618939399719,58.3,129,-3.7,40.9,8600,0.8,3.2800000000000002,Africa,Arabic,33986655
Azerbaijan,85,5.234000205993651,1.1536017656326298,1.15240025520325,0.5407757759094239,0.39815583825111406,0.0452693402767181,0.180987507104874,1.7624816894531203,78.2,102,-1.4,33.7,17500,13,3.64,Asia,Azerbaijani,9961396
Dominican Republic,86,5.230000019073491,1.07937383651733,1.4024167060852097,0.574873745441437,0.55258983373642,0.186967849731445,0.113945253193378,1.3194651603698702,61.3,82,-2.1,47.1,16900,3.3,0.64,Central America and the Caribbean,Spanish,10734247
Greece,87,5.2270002365112305,1.28948748111725,1.23941457271576,0.8101989030838009,0.0957312509417534,0.0,0.043289776891470004,1.74922156333923,69.1,120,-1.3,36.7,27700,1.1,2.4,Europe,Greek,10768477
Lebanon,88,5.22499990463257,1.07498753070831,1.1296242475509601,0.7350810766220089,0.28851598501205394,0.26445075869560203,0.037513829767704,1.69507384300232,76.1,79,-9.7,,19400,4.5,2.91,Middle East,Arabic,6229794
Portugal,89,5.19500017166138,1.3151752948761002,1.36704301834106,0.795843541622162,0.498465299606323,0.0951027125120163,0.0158694516867399,1.10768270492554,70.4,109,-1.8,33.9,30400,1.6,1.8399999999999999,Europe,Portuguese,10839514
Bosnia and Herzegovina,90,5.18200016021729,0.982409417629242,1.0693359375,0.705186307430267,0.204403176903725,0.328867495059967,0.0,1.89217257499695,69.3,89,-1.1,33.8,12700,1.3,0.99,Europe,Bosnian,3856181
Honduras,91,5.1810002326965305,0.730573117733002,1.14394497871399,0.582569479942322,0.348079860210419,0.23618887364864302,0.0733454525470734,2.0658111572265603,30,91,-3.1,47.1,5600,3.9,1.5899999999999999,Central America and the Caribbean,Spanish,9038741
Macedonia,92,5.175000190734861,1.06457793712616,1.20789301395416,0.644948184490204,0.325905978679657,0.25376096367836,0.0602777935564518,1.6174693107605,,101,-3,33.7,14900,1.4,0.9,Europe,Macedonian,2103721
Somalia,93,5.151000022888179,0.0226431842893362,0.7211513519287109,0.11398913711309401,0.602126955986023,0.291631311178207,0.28241032361984303,3.11748456954956,1.9,60,-0.1,,,1.5,,Africa,Somali,11031386
Vietnam,94,5.07399988174438,0.7885475754737851,1.27749133110046,0.6521689891815191,0.571055591106415,0.23496805131435397,0.0876332372426987,1.46231865882874,52.7,125,-2.3,34.8,6900,3.5,2.44,Southeast Asia,Vietnamese,96160163
Nigeria,95,5.07399988174438,0.783756256103516,1.21577048301697,0.0569157302379608,0.394952565431595,0.23094719648361198,0.0261215660721064,2.36539053916931,25.7,76,-2.1,48.8,5900,16.5,0.43,Africa,English,190632261
Tajikistan,96,5.04099988937378,0.524713635444641,1.27146327495575,0.5292351245880129,0.47156670689582797,0.24899764358997303,0.14637714624404902,1.8490493297576898,20.5,111,-1.4,32.6,3200,7.3,1.19,Asia,Tajik,8468555
Bhutan,97,5.01100015640259,0.885416388511658,1.3401265144348102,0.495879292488098,0.5015376806259161,0.474054545164108,0.17338038980960802,1.14018440246582,41.8,96,-5.4,38.8,8700,3.4,,Asia,Sharchhopka,758288
Kyrgyzstan,98,5.0040001869201705,0.5962200760841371,1.39423859119415,0.553457796573639,0.454943388700485,0.42858037352562,0.0394391790032387,1.5367231369018601,34.5,127,-3.6,33.4,3700,3.2,3.15,Asia,Kyrgyz,5789122
Nepal,99,4.961999893188481,0.479820191860199,1.17928326129913,0.504130780696869,0.44030594825744607,0.39409616589546204,0.0729755461215973,1.8912410736084,19.7,109,-9.8,32.8,2700,4.5,1.52,Asia,Nepali,29384297
Mongolia,100,4.95499992370605,1.0272358655929599,1.4930112361908001,0.557783484458923,0.39414396882057207,0.338464230298996,0.0329022891819477,1.1112923622131299,22.3,127,-6.4,34,13000,4.6,0.92,Asia,Mongolian,3068243
South Africa,101,4.8289999961853,1.05469870567322,1.38478863239288,0.18708007037639604,0.479246735572815,0.13936237990856198,0.0725094974040985,1.51090860366821,54,168,-3.2,62.5,13500,5.3,1.07,Africa,isiZulu,54841552
Tunisia,102,4.80499982833862,1.00726580619812,0.8683514595031742,0.613212049007416,0.289680689573288,0.0496933571994305,0.0867231488227844,1.8902511596679699,50.9,126,-4.8,40,11800,5.3,2.32,Africa,Arabic,11403800
Palestinian Territories,103,4.77500009536743,0.716249227523804,1.1556471586227401,0.565666973590851,0.25471106171608,0.114173173904419,0.0892826020717621,1.8788902759552,57.4,150,0.4,34.5,4300,0.8,,Middle East,Arabic,2747943
Egypt,104,4.7350001335144,0.989701807498932,0.997471392154694,0.520187258720398,0.28211015462875394,0.128631442785263,0.114381365478039,1.70216107368469,39.2,106,-10.8,31.8,12700,23.5,2,Africa,Arabic,97041072
Bulgaria,105,4.71400022506714,1.1614590883255,1.4343794584274299,0.708217680454254,0.28923171758651695,0.113177694380283,0.0110515309497714,0.996139287948608,59.8,120,0.8,40.2,21700,1.2,1.53,Europe,Bulgarian,7101510
Sierra Leone,106,4.70900011062622,0.36842092871666,0.984136044979095,0.005564753897488121,0.318697690963745,0.293040901422501,0.0710951760411263,2.66845989227295,11.8,102,-7.1,34,1600,18,0.81,Africa,English,6163195
Cameroon,107,4.69500017166138,0.564305365085602,0.946018218994141,0.132892116904259,0.430388748645782,0.23629845678806302,0.0513066314160824,2.3336455821991,25,79,-5.9,44.6,3700,0.6000000000000001,1.6,Africa,major African language groups,24994885
Iran,108,4.69199991226196,1.15687310695648,0.7115512490272521,0.639333188533783,0.24932260811328896,0.387242913246155,0.048761073499918005,1.49873495101929,44.1,106,-2.1,44.5,20200,9.9,2.69,Middle East,Persian,82021564
Albania,109,4.64400005340576,0.996192753314972,0.8036852478981021,0.731159746646881,0.381498634815216,0.20131294429302202,0.0398642159998417,1.49044156074524,66.4,115,-2.1,29,12500,2,1.22,Europe,Albanian,3047987
Bangladesh,110,4.60799980163574,0.586682975292206,0.735131740570068,0.533241033554077,0.478356659412384,0.17225535213947304,0.123717859387398,1.9787361621856698,18.2,92,-5,32.1,4200,5.7,1.44,Asia,Bangla,157826578
Namibia,111,4.57399988174438,0.964434325695038,1.0984708070755,0.33861181139946,0.520303547382355,0.0771337449550629,0.0931469723582268,1.4818902015686002,31,107,-6.3,59.7,11300,6.1,4.44,Africa,Oshivambo languages,2484780
Kenya,112,4.55299997329712,0.560479462146759,1.0679507255554201,0.30998834967613204,0.45276376605033897,0.444860309362411,0.0646413192152977,1.6519021987915001,26,90,-11.7,48.5,3500,8,1.4,Africa,English,47615739
Mozambique,113,4.550000190734861,0.23430564999580397,0.870701014995575,0.10665443539619399,0.48079109191894503,0.322228103876114,0.17943638563156103,2.3556509017944305,17.5,45,-6.9,45.6,1200,15.3,1.03,Africa,Emakhuwa,26573706
Myanmar,114,4.54500007629395,0.36711055040359497,1.12323594093323,0.397522568702698,0.514492034912109,0.8380751609802249,0.188816204667091,1.11529040336609,25.1,87,-3.3,,6200,5.1,4.08,Southeast Asia,Burmese,55123814
Senegal,115,4.53499984741211,0.479309022426605,1.17969191074371,0.409362852573395,0.37792226672172496,0.183468893170357,0.11546044796705199,1.78964614868164,25.7,107,-3.8,40.3,2700,1.4,1.8900000000000001,Africa,French,14668522
Zambia,116,4.513999938964839,0.6364067792892459,1.00318729877472,0.25783589482307395,0.461603492498398,0.249580144882202,0.0782135501503944,1.82670545578003,25.5,84,-8.4,57.5,4000,6.6,1.53,Africa,Bemba,15972001
Iraq,117,4.49700021743774,1.1027104854583702,0.978613197803497,0.501180469989777,0.288555532693863,0.19963726401329,0.10721575468778599,1.31890726089478,21.2,85,-11,,17000,0.1,3.63,Middle East,Arabic,39192111
Gabon,118,4.46500015258789,1.1982102394104,1.1556202173233001,0.35657858848571794,0.31232857704162603,0.0437853783369064,0.0760467872023582,1.3229162693023702,48.1,150,-6,42.2,19200,3,1.43,Africa,French,1772255
Ethiopia,119,4.46000003814697,0.339233845472336,0.8646692037582401,0.35340970754623396,0.408842742443085,0.31265074014663696,0.16545571386814098,2.01574373245239,15.4,59,-3.2,33,2200,9.9,0.67,Africa,Oromo,105350020
Sri Lanka,120,4.44000005722046,1.00985014438629,1.25997638702393,0.625130832195282,0.561213254928589,0.49086356163024897,0.0736539661884308,0.41938924789428705,32.1,126,-4.8,39.2,12800,6.5,2.14,Asia,Sinhala,22409381
Armenia,121,4.37599992752075,0.900596737861633,1.00748372077942,0.637524425983429,0.198303267359734,0.0834880918264389,0.0266744215041399,1.5214991569518999,62,115,-3.4,31.5,9500,0.9,4.09,Asia,Armenian,3045191
India,122,4.31500005722046,0.7922212481498722,0.754372596740723,0.455427616834641,0.469987004995346,0.23153848946094502,0.0922268852591515,1.5191171169281,29.5,91,-4.1,35.2,7200,3.6,2.47,Asia,Hindi,1281935911
Mauritania,123,4.29199981689453,0.6484572887420649,1.2720308303833001,0.285349279642105,0.0960980430245399,0.201870024204254,0.136957004666328,1.65163731575012,18,108,-1.1,37,4400,2.3,2.9699999999999998,Africa,Arabic,3758571
Congo (Brazzaville),124,4.29099988937378,0.8089642524719242,0.8320443630218509,0.28995743393898,0.4350258708000179,0.12085212767124198,0.0796181336045265,1.7241356372833299,7.6,102,-10.5,48.9,6600,0.5,7.17,Africa,French,4954674
Georgia,125,4.28599977493286,0.950612664222717,0.57061493396759,0.649546980857849,0.309410035610199,0.0540088154375553,0.25166663527488703,1.50013780593872,50,116,-3.9,40.1,10700,6,2.23,Asia,Georgian,4926330
Congo (Kinshasa),126,4.2800002098083505,0.0921023488044739,1.22902345657349,0.191407024860382,0.235961347818375,0.246455833315849,0.0602413564920425,2.22495865821838,3.8,42,-0.30000000000000004,42.1,800,41.5,1.34,Africa,French,83301151
Mali,127,4.19000005722046,0.476180493831635,1.2814733982086202,0.16936567425727803,0.306613743305206,0.183354198932648,0.10497024655342098,1.66819095611572,11.1,113,-3.4,40.1,2200,1.8,2.63,Africa,French,17885245
Ivory Coast,128,4.17999982833862,0.6030489206314089,0.904780030250549,0.0486421696841717,0.4477061927318571,0.201237469911575,0.130061775445938,1.84496426582336,26.5,131,-4.4,41.5,3900,0.8,1.18,Africa,French,24184810
Cambodia,129,4.1680002212524405,0.6017650961875921,1.00623834133148,0.429783403873444,0.633375823497772,0.385922968387604,0.0681059509515762,1.04294109344482,25.6,115,-1.9,37.9,4000,2.9,1.85,Southeast Asia,Khmer,16204486
Sudan,130,4.138999938964839,0.6595166921615601,1.21400856971741,0.290920823812485,0.0149958552792668,0.182317450642586,0.089847519993782,1.6870658397674598,28,77,-4.4,,4600,32.4,,Africa,Arabic,37345935
Ghana,131,4.11999988555908,0.667224824428558,0.873664736747742,0.29563772678375205,0.423026293516159,0.25692394375801103,0.0253363698720932,1.57786750793457,34.7,134,-6.9,42.3,4700,12.4,0.4,Africa,Asante,27499924
Ukraine,132,4.09600019454956,0.89465194940567,1.39453756809235,0.575903952121735,0.12297477573156401,0.270061463117599,0.0230294708162546,0.8143823146820072,52.5,127,-3.2,25.5,8700,14.4,3.5,"Asia, Europe",Ukrainian,44033874
Uganda,133,4.08099985122681,0.381430715322495,1.12982773780823,0.21763260662555703,0.443185955286026,0.32576605677604703,0.057069718837738,1.526362657547,45.9,63,-1.1,39.5,2400,5.6,1.57,Africa,English,39570125
Burkina Faso,134,4.03200006484985,0.35022771358490007,1.04328000545502,0.21584425866603896,0.32436785101890603,0.250864684581757,0.12032810598611803,1.72721290588379,14,89,-5.3,39.5,1900,0.4,1.23,Africa,French,20107509
Niger,135,4.02799987792969,0.16192533075809498,0.993025004863739,0.26850500702858,0.36365869641304,0.22867384552955602,0.13857294619083402,1.87398338317871,4.3,46,-4.4,34,1200,2.4,4,Africa,French,19245344
Malawi,136,3.97000002861023,0.233442038297653,0.5125688314437871,0.315089583396912,0.466914653778076,0.28717046976089505,0.0727116540074348,2.08178615570068,9.6,40,-3.9,46.1,1200,11.5,0.61,Africa,English,19196246
Chad,137,3.9360001087188703,0.43801298737525896,0.953855872154236,0.0411347150802612,0.16234202682972002,0.21611385047435802,0.0535818822681904,2.07123804092407,5,52,-3.5,43.3,2300,-0.9,2.79,Africa,French,12075985
Zimbabwe,138,3.875,0.37584653496742204,1.08309590816498,0.19676375389099102,0.336384207010269,0.189143493771553,0.0953753814101219,1.59797024726868,23.1,102,-7,43.2,2300,1.3,2.2,Africa,Shona,13805084
Lesotho,139,3.80800008773804,0.521021246910095,1.19009518623352,0.0,0.390661299228668,0.157497271895409,0.119094640016556,1.42983531951904,27.4,122,-3.8,63.2,3600,5.6,1.85,Africa,Sesotho,1958042
Angola,140,3.79500007629395,0.8584281802177429,1.1044119596481299,0.0498686656355858,0.0,0.09792649000883098,0.0697203353047371,1.6144824028015101,13,45,-7.3,42.7,6800,31.7,2.95,Africa,Portuguese,29310273
Afghanistan,141,3.7939999103546103,0.401477217674255,0.581543326377869,0.18074677884578697,0.106179520487785,0.311870932579041,0.0611578300595284,2.15080118179321,10.6,70,-14.5,,2000,5,0.89,Asia,Afghan Persian or Dari,34124811
Botswana,142,3.7660000324249303,1.12209415435791,1.2215549945831299,0.34175550937652605,0.505196332931519,0.0993484482169151,0.0985831990838051,0.37791371345520003,39.4,146,-2.8,60.5,17800,3.3,3.37,Africa,Setswana,2214858
Benin,143,3.65700006484985,0.43108540773391707,0.43529984354972795,0.20993021130561804,0.42596277594566295,0.207948461174965,0.0609290152788162,1.88563096523285,12,79,-9.4,36.5,2300,0.1,1.1400000000000001,Africa,French,11038805
Madagascar,144,3.64400005340576,0.305808693170547,0.9130203723907471,0.375223308801651,0.18919676542282102,0.208732530474663,0.0672319754958153,1.58461260795593,4.7,35,-2.3,41,1600,8.1,0.53,Africa,French,25054161
Haiti,145,3.6029999256133998,0.368610262870789,0.640449821949005,0.277321130037308,0.0303698573261499,0.48920378088951094,0.0998721495270729,1.69716763496399,12.2,61,-8,60.8,1800,14.7,,Central America and the Caribbean,French,10646714
Yemen,146,3.59299993515015,0.5916834473609921,0.93538224697113,0.310080915689468,0.24946372210979503,0.104125209152699,0.0567674227058887,1.3456006050109899,24.6,59,-6.9,37.9,1300,4.9,3.9699999999999998,Middle East,Arabic,28036829
South Sudan,147,3.5910000801086404,0.39724862575531,0.601323127746582,0.163486003875732,0.147062435746193,0.285670816898346,0.116793513298035,1.8795673847198502,,12,-1.3,46,1500,187.9,10.93,Africa,English,13026129
Liberia,148,3.5329999923706095,0.11904179304838199,0.8721179366111759,0.229918196797371,0.33288118243217496,0.26654988527298,0.0389482490718365,1.6732859611511202,7.3,66,-4.7,32,1400,12.4,0.62,Africa,English,4689021
Guinea,149,3.50699996948242,0.24454993009567302,0.7912446856498722,0.194129139184952,0.348587512969971,0.264815092086792,0.110937617719173,1.55231189727783,9.8,87,-3.4,39.4,2000,8.9,2.49,Africa,French,12413867
Togo,150,3.4949998855590803,0.30544471740722695,0.4318825304508211,0.247105568647385,0.38042613863945,0.19689615070819896,0.0956650152802467,1.8372292518615703,11.3,78,-4.8,46,1700,-0.7000000000000001,1.8599999999999999,Africa,French,7965055
Rwanda,151,3.47099995613098,0.368745893239975,0.945707023143768,0.326424807310104,0.5818438529968261,0.25275602936744695,0.455220013856888,0.540061235427856,29.8,74,-4.3,50.4,2100,4.8,1.21,Africa,Kinyarwanda,11901484
Syria,152,3.46199989318848,0.777153134346008,0.396102607250214,0.5005333423614501,0.0815394446253777,0.49366372823715204,0.15134713053703303,1.06157350540161,31.9,87,-8.7,,2900,25.5,,Middle East,Arabic,18028549
Tanzania,153,3.34899997711182,0.511135876178741,1.04198980331421,0.364509284496307,0.390017777681351,0.354256361722946,0.0660351067781448,0.621130466461182,13,74,-2.7,37.6,3200,5.3,1.1400000000000001,Africa,Kiswahili or Swahili,53950935
Burundi,154,2.90499997138977,0.09162256866693501,0.629793584346771,0.151610791683197,0.0599007532000542,0.20443518459796897,0.0841479450464249,1.68302416801453,5.2,52,-4.2,42.4,700,16.6,2.21,Africa,Kirundi,11466756
Central African Republic,155,2.69300007820129,0.0,0.0,0.0187726859003305,0.270842045545578,0.280876487493515,0.0565650761127472,2.06600475311279,4.6,22,-2,43.6,700,3.8,,Africa,French,5625118
##############
# Question 1 #
##############
# Define sort function
def sort_list(l):
pass
##############
# Question 2 #
##############
# Given a random number and a random digit, design an algorithm to place the
# digit so that the number is divisible by 3
def div7(n, i):
pass
##############
# Question 3 #
##############
# Extend the cubic function y = a_1 x^3 + a_2 x^2 + a_3 x + a_4 to handle a
# multi-variate input
def cubic(x, A):
import numpy as np
pass
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Q2.1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Use `matplotlib` to show scatterplots of each variable"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
"import numpy as np\n",
"#import pandas as pd\n",
"\n",
"# you can also use pandas to load the data\n",
"data = np.loadtxt('happiness.csv', skiprows=1, delimiter=',', converters = {3: lambda s: float(s[1])})\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"{replace this text with your explanation text about trends in each plot}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"{replace this text with which factors you think are important and why}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Q2.2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load data and set up packages"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.kernel_ridge import KernelRidge\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.model_selection import RepeatedKFold"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check the dataset for missing values and, if any are found, address them programmatically"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Linear model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"{text results here}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Quadratic model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"{text results here}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Gaussian model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"{text results here}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Comparison"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"{replace with your comparison paragraph/images}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
#!/usr/bin/env sh
python -m pytest
import numpy as np
import l1p1
def test_case_1():
x = np.array([1, 2, 3, 4])
A = np.array([[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]])
assert l1p1.cubic(x, A) == 45
from hypothesis import given, settings, unlimited
import hypothesis.strategies as st
import l1p1
def test_case_1():
v = l1p1.div7(123, 4)
assert (v%7) == 0
assert v == 4123
def test_case_2():
v = l1p1.div7(39, 2)
assert (v%7) == 0
assert v == 329
@given(st.integers(min_value=10), st.integers(min_value=0, max_value=9))
def test_digit_order(n, i):
assert i < n
@given(st.integers(min_value=10), st.integers(min_value=0, max_value=9))
def test_div_by_7(n, i):
# don't worry about errors
try:
assert l1p1.div(n, i) % 7 == 0
except Exception as e:
assert str(e) == "not possible"
from hypothesis import given, settings, unlimited
import hypothesis.strategies as st
import l1p1
def is_sorted(l):
if(len(l) < 2):
return True
else:
return all([x<=y for x,y in zip(l[:-1],l[1:])])
def test_simple_sort():
l = [3, 6, 1, 4]
l_sorted = [1, 3, 4, 6]
assert l1p1.sort_list(l) == l_sorted
def test_already_sorted():
l = [1, 2, 3, 4, 5]
assert l1p1.sort_list(l) == l
def test_reverse_sorted():
l = [5, 4, 3, 2, 1]
assert l1p1.sort_list(l) == reversed(l)
@given(st.lists(st.integers()))
def test_random_lists(l):
assert is_sorted(l1p1.sort_list(l))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment