查看: 3371| 回复: 12
跳转到指定楼层
上一主题 下一主题
收起左侧

DS: SQL + Leetcode + Model 每日打卡贴!

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
去年年底IE毕业仍然在找data相关的工作,想要GHC的时候再拼一拼,每日打卡鞭策一下自己!. ----
有想要去GHC的盆友,一起抢票一起准备呀!. 1point 3 acres
Day1:
SQL:
Data question: dialog log (userid int appid int type char, a flag either "imp" or "click" ds timestamp ) How would you access the quality of the app? How to compute the click-through rate (in MySQL)?


Assuming CRT is defined as total number of clicks / total number of impressions :. check 1point3acres for more.
.--
select appid, total_click_ct / total_imp_ct as CTR
from (
    select
        appid,
        count(distinct case when flag = 'imp' then 1 else 0 end) as total_imp_ct,
        count(distinct case when flag = 'click' then 1 else 0 end) as total_click_ct,
    from table
    where time=..
    group by appid) table2
order by CTR desc;

Assessing the quality of an app, some ideas: (From GLassdoor)

if it's your company's app, you can look at numbers of downloads and server traffic. You can survey your users, measure profitability, and track how often your users refer others to get the app.

if it's not your app, you can look at ratings in the app store, cost, read reviews, and look at how well it does against your competitors' cost and ratings..1point3acres

you can look at specific features: does it do what's needed? does it look good? does it have a bunch of unnecessary features that nobody uses or wants? Does it clutter up your storage or run very slowly, i.e. is it optimized?. ----

you can look at the company's reputation, if you don't know anything about them, look at their website, does it look professional? does it have demos? can you test the app with a free trial before you buy?


Leetcode: 203. Remove Linked List Elements. 1point3acres.com
class Solution(object):
    def removeElements(self, head, val):
        """
        :type head: ListNode
        :type val: int
        :rtype: ListNode
        """. From 1point 3acres bbs
        while head.val==val and head != None:
            new_node=head.next
            return new_node
        
        curr=head
        while (curr!=None):
            if curr.next!=None and curr.next.val==val:
                curr.next=curr.next.next
            else:
..                 curr=curr.next
        return head

ML: decision tree <-bagging tree <- random forest <-boosted trees
decision tree: 1. feature prioritization + 2. feature splitting.
At each iteration, we split the feature which can give us the largest entropy gain. The same procedure is performed on each split until RSS  can no longer be decreased or meet the stopping criteria(leaf size, depth)
high variance, low bias

bagging tree:  为了保证抽取的数据是同一个分布,有放回的抽样,create B decision trees trained on B bootstrapped training sets. The predicted value is the avg value of all B trees.
moderate variance, low bias.. check 1point3acres for more.
when bootstrap, we can only select 2/3 of the data.

random forest: bootstrapped training sets+ multiple trees + random choice of features.
uses: feature importance, first cut model
. 1point 3acres
AdaBoost: fit a sequence of weak learners on repeatedly modified versions of the data
The predictions from all of them are then combined through a weighted majority vote to produce the final prediction.

Gradient Boosting: fit a decision tree using the current residuals rather than the outcome Y as the response.


评分

参与人数 2大米 +2 收起 理由
qxtracy + 1 给你点个赞!
shiningBloom + 1 赞一个

查看全部评分


上一篇:请教 data science里哪几个方向比较靠谱?
下一篇:文科生试图转data 资料准备清单,求各位建议~
全局:
现在ds工作这么难找么
回复

使用道具 举报

推荐
 楼主| Blanchey218 2019-5-16 12:33:14 | 只看该作者
全局:
Day 4:

SQL:
We have a table with users, their country and when they created the account. We want to find: The country with the largest and smallest number of users A query that returns for each country the first and the last user who signed up (if that country has just one user, it should just return that single user)
1. SELECT country, user_count
    FROM ( .1point3acres
                SELECT *,  ROW_NUMBER() OVER (ORDER BY user_count) count_asc,                        
                ROW_NUMBER() OVER (ORDER BY user_count desc) count_desc           
                FROM (              
                             SELECT country, COUNT(distinct user_id) as user_count                        
                             FROM query                        
                             GROUP BY country ) a ) tmp
      WHERE count_asc = 1 or count_desc = 1;

2. SELECT user_id, created_at, country
    FROM (           
    SELECT *,  ROW_NUMBER() OVER (PARTITION BY country ORDER BY created_at) count_asc,           
                     ROW_NUMBER() OVER (PARTITION BY country ORDER BY created_at desc) count_desc            
                      FROM query) tmp. From 1point 3acres bbs

Leetcode:.
Merge Sort: 先分再合,平均分,recursion 先split直到只有一个数字的时候,开始merge
先focus左子树。 merge: 两个指针指向子集的第一个位置,进行比较,小的那个放在心底集合i,对应的index往后移动i+1,跟j指向的数进行比较...有一个子集全部走完,就把剩下的都放进去。
class Solution(object):
  def mergeSort(self, array):
    """
    input: int[] array. 1point 3acres
    return: int[]
    """
    # write your solution here.google  и
    if len(array)==0 or len(array)==1:
      return array
   
    middle=len(array)/2
    left=self.mergeSort(array[:middle])
    right=self.mergeSort(array[middle:])
    return self.merge(left,right)
  
  def merge(self,left,right):.--
    i=j=0.--
    result=[]
    while i < len(left) and j<len(right):
      if left[i]<right[j]:
        result.append(left[i])
        i=i+1
      else:
        result.append(right[j])
        j=j+1
    while i<len(left):
      result.append(left[i]).google  и
      i+=1
    while j<len(right):
      result.append(right[j])
      j+=1
    return result
   
ML:
SVM
可以解决的问题和变量类型 classification & regression problem
                                          continuous & categorical variables
The core idea of SVM is to find a maximum marginal hyperplane(MMH) that best divides the dataset into classes.
Support Vectors
Support vectors are the data points, which are closest to the hyperplane. These points will define the separating line better by calculating margins. These points are more relevant to the construction of the classifier.

Hyperplane
A hyperplane is a decision plane which separates between a set of objects having different class memberships.
Margin
A margin is a gap between the two lines on the closest class points. This is calculated as the perpendicular distance from the line to support vectors or closest points. If the margin is larger in between the classes, then it is considered a good margin, a smaller margin is a bad margin.

Dealing with non-linear and inseparable planes
SVM uses a kernel trick to transform the input space to a higher dimensional space as shown on the right.
Tuning Hyperparameters: 不同的kernel类型以及他们适用的场景
Linear Kernel, Polynomial Kernel, Radial Basis Function Kernel
Margin-width(C-parameter), Kernel parameter(gamma, degree)
if we force the margin to be too small, it is prone to overfitting.

Not susceptible to outliers Only support vectors determine the separation hyperplane
and the margin width is determined by points closest to the plane.


. From 1point 3acres bbs

. From 1point 3acres bbs
回复

使用道具 举报

推荐
 楼主| Blanchey218 2019-5-10 12:43:31 | 只看该作者
全局:
第二天:
SQL:Nth Highest Salary
CREATE FUNCTION getNthHighestSalary(@N INT) RETURNS INT AS
BEGIN.1point3acres
    RETURN (
      select distinct salary from . From 1point 3acres bbs
(select salary, dense_rank () over(order by salary desc) as salary_rank
from employee) as sub. 1point3acres
where salary_rank= @N
    );
END
. Χ
Leetcode:
2. Add Two Numbers:
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
Explanation: 342 + 465 = 807.

class Solution(object):
    def addTwoNumbers(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """. 1point3acres.com
        dummy = cur = ListNode(0). 1point3acres
        carry = 0
        
        while l1 and l2:
            tem_sum=l1.val+l2.val+carry. Waral dи,
            carry=tem_sum/10
            cur.next = ListNode(tem_sum%10)
            cur = cur.next
            l1=l1.next
. check 1point3acres for more.            l2=l2.next
            
        while l1:
            tem_sum=l1.val+carry. check 1point3acres for more.
            carry=tem_sum/10
            cur.next = ListNode(tem_sum%10) .--
            cur = cur.next
            l1=l1.next
            .1point3acres
        while l2:
            tem_sum=l2.val+carry
            carry=tem_sum/10
            cur.next = ListNode(tem_sum%10)
            cur = cur.next.1point3acres
            l2=l2.next
        if carry>0:
            cur.next=ListNode(carry)
        return dummy.next

ML: Linear Regression
4 assumption: there is a linear relationship between the independent and dependent variables. ..
• The errors, εi, are Independent of x.
• The errors, εi, are Normally distributed.
ε ~ Ν(0, σ2) and independent of X
• assume constant variance in observations

Regularized Regression: L1(Lasso) L2(Ridge)

Coefficient Interpret: the change in the predicted value with a 1 unit increase in the predictor value holding all other variables constant.

How to evaluate the regression:
R^2=1- RSS/TSS
of the variation in y is 'explained by' the variation in predictor x.
值越接近1,就证明线性拟合的越好。.

Outliers: 1.5* IOR threshold


回复

使用道具 举报

全局:
GHC是啥呀
回复

使用道具 举报

🔗
 楼主| Blanchey218 2019-5-10 11:27:37 | 只看该作者
全局:
KaWing 发表于 2019-5-9 14:28. check 1point3acres for more.
GHC是啥呀

Grace Hopper Celebration
回复

使用道具 举报

🔗
 楼主| Blanchey218 2019-5-10 11:28:49 | 只看该作者
全局:
Lenin 发表于 2019-5-9 12:11
. ----现在ds工作这么难找么
. From 1point 3acres bbs
可能我简历不够好,接到的面试比较少哭 伤心
回复

使用道具 举报

🔗
qxtracy 2019-5-10 22:11:11 | 只看该作者
全局:
朋友你好认真!感觉可以来你这里跟着一起监督自己打卡哈哈
回复

使用道具 举报

🔗
 楼主| Blanchey218 2019-5-11 12:54:59 | 只看该作者
全局:
qxtracy 发表于 2019-5-10 22:11
朋友你好认真!感觉可以来你这里跟着一起监督自己打卡哈哈

哈哈哈!一起呢!
回复

使用道具 举报

🔗
 楼主| Blanchey218 2019-5-11 12:55:21 | 只看该作者
全局:
周五的没来得及,明天我睡起来补上!
回复

使用道具 举报

🔗
qxtracy 2019-5-11 23:19:50 | 只看该作者
全局:
Blanchey218 发表于 2019-5-11 12:55
周五的没来得及,明天我睡起来补上!

你太认真了 我周五都玩去了233
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表