12
返回列表 发新帖
楼主: Blanchey218
跳转到指定楼层
上一主题 下一主题
收起左侧

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

🔗
 楼主| Blanchey218 2019-5-12 12:34:27 | 只看该作者
全局:
DAY 3:
SQL: Weather Observation Station 20 in Hackerrank
Query the median of the Northern Latitudes (LAT_N) from STATION and round your answer to decimal places.

Solution:
SELECT cast(AVG(LAT_N) as decimal(10,4) )
FROM (select LAT_N, ROW_NUMBER() OVER (ORDER BY LAT_N ) AS RN FROM STATION ) A
WHERE A.RN IN (SELECT CEILING(COUNT(LAT_N)/2.0) FROM STATION)
AND A.RN IN (SELECT FLOOR(COUNT(LAT_N)/2.0 +1) FROM STATION)


Leetcode:
876. Middle of the Linked List
-baidu 1point3acres
class Solution(object):
    def middleNode(self, head):
        """. ----
        :type head: ListNode
        :rtype: ListNode. Χ
        """
        tmp = head
        while tmp and tmp.next:
            head = head.next
            tmp = tmp.next.next
        return head
We need two pointers, one is head with one step each iteration, and the other is tmp with two steps each iteration. So when the tmp reaches the end of the list, the head just reaches the half of it, which is exactly what we want.

Model: Logistic Regression
In Logistic Regression, features are used to predict the probabilities of incoming data belonging to a particular class. The coefficient vector represents the change in the logit function for one unit of change in the feature.
Binary logistic regression is estimated using Maximum Likelihood Estimation (MLE)
Gradient Descent to get the optimized objective
Evaluation:
Confusion metric
F1= 2TP/(2TP+FP+FN)
Precision(PPV)=TP/(TP+FP)
false positive rate=FR/N
Recall/Sensitivity: TPR=TP/(TP+FN)
Accuracy=(TP+FN)/(P+N)
ROC Curve: the trade off between sensitivity and false positive rate as the prediction threshold changes.. ----
AUC: The model will rank a randomly chosen positive instance higher than a randomly chosen negative instance..google  и
回复

使用道具 举报

🔗
 楼主| 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 . Waral dи,
    FROM (
                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
. 1point 3 acres
Leetcode:
Merge Sort: 先分再合,平均分,recursion 先split直到只有一个数字的时候,开始merge.google  и
先focus左子树。 merge: 两个指针指向子集的第一个位置,进行比较,小的那个放在心底集合i,对应的index往后移动i+1,跟j指向的数进行比较...有一个子集全部走完,就把剩下的都放进去。
class Solution(object):. Χ
  def mergeSort(self, array):. From 1point 3acres bbs
    """
    input: int[] array.1point3acres
    return: int[]
    """.
    # write your solution here
    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. 1point3acres.com
    while i<len(left):
      result.append(left[i]).google  и
      i+=1
    while j<len(right):
      result.append(right[j]). check 1point3acres for more.
      j+=1
    return result. 1point3acres
   
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.
. From 1point 3acres bbs
Hyperplane. check 1point3acres for more.
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.. .и
.1point3acres
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.. Χ




. 1point3acres
回复

使用道具 举报

🔗
toutmio 2022-2-25 05:53:35 | 只看该作者
全局:
楼主你好,想问一下你面过teladoc的ds吗?在某个帖子看到的就过来问问,打扰了
回复

使用道具 举报

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

本版积分规则

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