中级农民
- 积分
- 239
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2016-3-22
- 最后登录
- 1970-1-1
|
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
|
|