注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
大家好,发一个脸家Data Infra的数据科学家电面,大家给我加米哈。问题之后是我给的答案,答案不一定对哈(否则也不会挂了555),如果我答错的地方还请大家指出,我也可以学习提高。我这贴几乎是列了完整的原题为了造福地里的小伙伴,还请脸家的小伙伴看到后不要举报我哈。
第一部分:Data manipulation:
给两张表
table user_age
userid, age, country
1, 27, 'India'
2, 35, 'China'
5, 23, 'US'
44, 47, 'Italy'
...
table user_names . 1point3acres
userid, name. 1point3acres.com
1,'peter' . .и
2,'brian'.google и
5,'mark'
3,'david'-baidu 1point3acres
55,'sheryl'
...
1. 列出所有平均年龄超过45岁的国家.
. 1point 3acres
- select country from user_age
- group by country
- having avg(age)>45
-
复制代码
2. 列出所有不重名(names are unique)的userids.
- select userid from user_names
- where name in
- (select name from user_names
- group by name
- having count(name)=1)
复制代码
3. 找出所有distinct的名字相同的userid pair, 输出格式为 userid_1, userid_2, name. 有可能有超过2人以上具有相同的名字,需要列出所有可能的组合
(1,4,mark) (2,3,mark)(2,6,mark)....
- select u1.userid,u2.userid,u1.name from user_names as u1, user_names as u2
- where u1.name = u2.name and u1.userid<u2.userid
复制代码
第二部分:Coding
根据以下的输入,
给定列表作为输入,编写一个函数来处理它们,并为任何结束的好友关系(friendship)返回其的开始和结束日期。 . 1point 3acres
Assumption: . 1point3acres
*对于输入而言,确保每一个将被删除的好友关系在删除之前已经建立。
*每个用户都是独一无二的。例如,一个人不能要求与自己成为朋友。
输入格式(actor_id, receiver_id, timestamp) 输入的vector不保证是按时间戳排序的。
accepts = [(1, 2, '2000-02-11'), (3, 4, '2004-12-21'), (1, 2, '2009-09-21')]
removes = [(2, 1, '2009-03-19'), (1, 2, '2010-03-30')]
输出格式: (friend_id1, friend_id2, start_date, end_date) . From 1point 3acres bbs
-baidu 1point3acres
[(1, 2, '2000-02-11', '2009-03-19'), (1, 2, '2009-09-21', '2010-03-30')]
- import heapq
- def friendship(accepts,removes):.
- # corner [] [].1point3acres
- res = []
- if len(accepts)==0 or len(removes)==0:
- return res
- friends = {}
- for x,y,date in accepts:
- if x>y:
- x,y = y,x
- if (x,y) not in friends:
- friends[(x,y)]=heapq.heapify([])
- heapq.heappush(friends[(x,y)],date)
- removes.sort(lambda x:x[2])
- for x,y,date in removes:
- if x>y:
- x,y = y,x
. 1point3acres.com - if (x,y) in friends:
- accept_date = heapq.heappop(friends[(x,y)])
- res.append((x,y,accept_date,date)). ----
- if len(friends[(x,y)]) ==0:
- del friends[(x,y)]
-baidu 1point3acres - return res
复制代码
第三部分 Case Study 和统计. check 1point3acres for more.
给如下数据表.google и
userid | timestamp | description | amount | balance | distance_from_home | fraudulent
----------------------------------------------- coefficients and standard errors)?
a vector of random variables is heteroscedastic if the variability of the random disturbance is different across elements of the vector.
Linear regression assume the input data is homoskedasticity. If not, the estimated model will be compromised.
Heteroscedasticity may not cause major bias in the coefficient estimates, it does make the coefficients less precise, which makes the coefficient estimates further from the correct value.
Heteroscedasticity tends to produce p-values that are smaller than they should be. This effect occurs because heteroscedasticity increases the variance of the coefficient estimates but the OLS procedure does not detect this increase. Therefore, it can lead a test score statistically significant when it is actually not significant.
To mitigate this issue, we can use some non-linear function to transform the data. Such non-linear function can be log function.
. check 1point3acres for more.
|