From https://unix.stackexchange.com/questions/108581/how-to-randomly-sample-a-subset-of-a-file
perl -ne 'print if (rand() < .01)' huge_file.csv > sample.csv
Just a collection of some random cool stuff. PS. Almost 99% of the contents here are not mine and I don't take credit for them, I reference and copy part of the interesting sections.
From https://unix.stackexchange.com/questions/108581/how-to-randomly-sample-a-subset-of-a-file
perl -ne 'print if (rand() < .01)' huge_file.csv > sample.csv
BOTORCH: A Framework for Efficient Monte-Carlo Bayesian Optimization
To address these problems, we developed BoTorch, a framework for Bayesian optimization research, and Ax, a robust platform for adaptive experimentation. BoTorch follows the same modular design philosophy as PyTorch, which makes it very easy for users to swap out or rearrange individual components in order to customize all aspects of their algorithm, thereby empowering researchers to do state-of-the art research on modern Bayesian optimization methods. By exploiting modern parallel computing paradigms on both CPUs and GPUs, it is also fast.
Core Data Science researchers discuss research award opportunity in adaptive experimentation
https://www.hackerrank.com/challenges/revising-the-select-query/problem
Easy
1. Query all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA.
select * from City where population > 100000 and CountryCode='USA'
2. Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA.
The CITY table is described as follows:
select Name from City where population > 120000 and CountryCode='USA'
3. Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer.
select distinct City from Station where mod(id,2)=0
Medium
1. Query an alphabetically ordered list of all names in OCCUPATIONS, immediately followed by the first letter of each profession as a parenthetical (i.e.: enclosed in parentheses). For example: AnActorName(A), ADoctorName(D), AProfessorName(P), and ASingerName(S).
select * from (select concat('There are a total of ',count(occupation),' ',lower(occupation),'s.') as stat from occupations group by occupation) as innertable order by innertable.stat;
2. Pivot the Occupation column in OCCUPATIONS so that each Name is sorted alphabetically and displayed underneath its corresponding Occupation. The output column headers should be Doctor, Professor, Singer, and Actor, respectively.
Note: Print NULL when there are no more names corresponding to an occupation.
https://codingsight.com/pivot-tables-in-mysql/
User nobuh:
select
max(if(occupation='Doctor', name, null)) as docname,
max(case when occupation='Professor' then name else null end) as profname,
max(case when occupation='Singer' then name else null end) as singername,
max(case when occupation='Actor' then name else null end) as actorname
from (
select
a.occupation,
a.name,
(select count(name) from occupations b where a.occupation=b.occupation and a.name > b.name) as name_rank
from occupations a
) as rank_summary
group by name_rank
order by name_rank
name_rank:
selecta.occupation,a.name,-- get the name rank by comparing the names(select count(name) from occupations b where a.occupation=b.occupation and a.name > b.name) as name_rankfrom occupations aorder by name_rank;
Doctor Aamina 0Actor Eve 0Singer Christeen 0Professor Ashley 0Doctor Julia 1Singer Jane 1Professor Belvet 1Actor Jennifer 1Actor Ketty 2Singer Jenny 2Doctor Priya 2Professor Britney 2Singer Kristeen 3Professor Maria 3Actor Samantha 3Professor Meera 4Professor Naomi 5Professor Priyanka 6
3. You are given a table, BST, containing two columns: N and P, where N represents the value of a node in Binary Tree, and P is the parent of N.
Write a query to find the node type of Binary Tree ordered by the value of the node. Output one of the following for each node:
Root: If node is root node.
Leaf: If node is leaf node.
Inner: If node is neither root nor leaf node.
Answer
select * from bst;select distinct '------' from bst;select * from (select n,'Root' from bst bo where bo.p is nullunion allselect n,'Inner' from bst bo where bo.p is not null and bo.n in (select bi.p from bst bi where p is not null)union allselect n,'Leaf' from bst bo where bo.p is not null and bo.n not in (select bi.p from bst bi where p is not null)) tmporder by n;
1 23 25 67 62 46 44 158 910 912 1314 139 1113 1111 1515 NULL------1 Leaf2 Inner3 Leaf4 Inner5 Leaf6 Inner7 Leaf8 Leaf9 Inner10 Leaf11 Inner12 Leaf13 Inner14 Leaf15 Root
4. Given the table schemas below, write a query to print the company_code, founder name, total number of lead managers, total number of senior managers, total number of managers, and total number of employees. Order your output by ascending company_code.
https://www.hackerrank.com/challenges/the-company/problem
SQL
select c.company_code,founder
,count(distinct lead_manager_code)
,count(distinct senior_manager_code)
,count(distinct manager_code)
,count(distinct employee_code)
from company c left join employee e on c.company_code=e.company_code group by c.company_code,founder
order by cast(substr(c.company_code,2,5) as UNSIGNED);
Output
C1 Monika 1 2 1 2
C2 Samantha 1 1 2 2
select format(lat_n,4) from (select s1.id,s1.lat_n,(select count(*) from station),(select cast(count(id)/2 as unsigned) from station) as mid_rank,(select count(s2.id) from station s2 where s1.lat_n > s2.lat_n) as latn_rank from station s1 order by s1.lat_n) as rank_tablewhere (latn_rank +1 )= mid_rank;
select round(s.lat_n,4) from station s where (select round(count(s.id)/2)-1 from station) = (select count(s1.id) from station s1 where s1.lat_n > s.lat_n);
83.8913
6. https://www.hackerrank.com/challenges/interviews/problem
https://www.w3schools.com/sql/func_mysql_date_add.asp
SELECT DATE_ADD("2017-06-15", INTERVAL 10 DAY); # returns 2017-06-25



| Term | Meaning | Common uses |
|---|---|---|
N, number of independent samples; t, the t-statistic; p, probability.
| ||
| Standard deviation (s.d.) | The typical difference between each value and the mean value. | Describing how broadly the sample values are distributed. s.d. = √−(∑ (x − mean)2/(N − 1)) |
| Standard error of the mean (s.e.m.) | An estimate of how variable the means will be if the experiment is repeated multiple times. | Inferring where the population mean is likely to lie, or whether sets of samples are likely to come from the same population. s.e.m. = s.d./√−N |
| Confidence interval (CI; 95%) | With 95% confidence, the population mean will lie in this interval. | To infer where the population mean lies, and to compare two populations. CI = mean ± s.e.m. × t(N−1) |
| Independent data | Values from separate experiments of the same type that are not linked. | Testing hypotheses about the population. |
| Replicate data | Values from experiments where everything is linked as much as possible. | Serves as an internal check on performance of an experiment. |
| Sampling error | Variation caused by sampling part of a population rather than measuring the whole population. | Can reveal bias in the data (if it is too small) or problems with conduct of the experiment (if it is too big). In binomial distributions (such as live and dead cell counts) the expected s.d. is √−(N × p × (1 − p)); in Poisson dist |