Zheng Chu's Blog

让希望永驻


  • 主页

  • 所有专栏

  • 历史文章

  • 标签

  • 关于我

Tensorfow2复习--技巧

Posted on 2020-07-04 Edited on 2020-12-06 In DeepLearning

Tensorfow2.0复习笔记:NLP

Tensorfow2复习--LowerAPI

Posted on 2020-07-04 Edited on 2020-12-06 In DeepLearning

Tensorfow2.0—LowerAPI

image-20200704184231346

image-20200704184431104

numpy to tensorflow

Notice that NumPy uses 64-bit precision by default, while Tensor‐ Flow uses 32-bit.

This is because 32-bit precision is generally more than enough for neural networks, plus it runs faster and uses less RAM.

Read more »

Tensorfow2复习--RNN

Posted on 2020-07-04 Edited on 2021-03-16 In DeepLearning

Tensorfow2.0—RNN

RNN cell

Input:Vector:$\mathbf{X}{t-1}$,$\mathbf{y}{t-1}$

a single layer, with a single neuron:

a single layer, with a sin‐ gle neuron

1
2
model = keras.models.Sequential([ keras.layers.SimpleRNN(1, input_shape=[None, 1])
])
Read more »

Python-Trick

Posted on 2020-06-30 Edited on 2020-12-15 In Python

可变对象与不可变对象

对象有两种,“可更改”(mutable)与“不可更改”(immutable)对象。在python中,strings, tuples, 和numbers是不可更改的对象,而 list, dict, set 等则是可以修改的对象。(这就是这个问题的重点)

所以,传入函数的是不可变对象,那函数会自动复制一份a的引用:

Read more »

精通c++的拼写

Posted on 2020-06-30 Edited on 2020-12-06 In C++

左右值

A useful heuristic to determine whether an expression is an lvalue is to ask if you can take its address. If you can, it typically is. If you can’t, it’s usually an rvalue. A nice feature of this heuristic is that it helps you remember that the type of an expression is independent of whether the expression is an lvalue or an rvalue.

Read more »

CodeWar

Posted on 2020-06-21 Edited on 2020-12-06 In 算法与数据结构

CodeWar-WEEK 2


14. 最长公共前缀

  • Scala
1
2
3
4
5
6
7
8
9
object Solution {
def longestCommonPrefix(strs: Array[String]): String = {
if(strs.isEmpty || strs.size == 0) return "";
for {i <- 0 to strs(0).size
s <- strs}
if (i >= s.size || strs(0).charAt(i) != s.charAt(i)) return s.substring(0, i);
strs(0);
}
}
Read more »

EnsembleLearning

Posted on 2020-06-20 Edited on 2020-12-06 In 机器学习

[toc]


last:2019-09-04 21:45:21

update: 2020-06-20

Voting:利用投票做分类

  • hard-voting:多个分类器的结果中选择重合数目最多的。

  • Soft-voting:会对预测的结果配上权重,使得预测结果最好的类别更大概率视为正确的。

  • 比如用LR、SVM、随机森林等模型组合在一起进行投票:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    from sklearn.ensemble import RandomForestClassifier
    from sklearn.ensemble import VotingClassifier
    from sklearn.linear_model import LogisticRegression
    from sklearn.svm import SVC

    log_clf = LogisticRegression(solver="lbfgs", random_state=42)
    rnd_clf = RandomForestClassifier(n_estimators=100, random_state=42)
    svm_clf = SVC(gamma="scale", random_state=42)

    voting_clf = VotingClassifier(
    estimators=[('lr', log_clf), ('rf', rnd_clf), ('svc', svm_clf)],
    voting='hard')

    """ Soft-voting
    voting_clf = VotingClassifier(
    estimators=[('lr', log_clf), ('rf', rnd_clf), ('svc', svm_clf)],
    voting='soft')
    """


    voting_clf.fit(X_train, y_train)
    from sklearn.metrics import accuracy_score

    for clf in (log_clf, rnd_clf, svm_clf, voting_clf):
    clf.fit(X_train, y_train)
    y_pred = clf.predict(X_test)
    print(clf.__class__.__name__, accuracy_score(y_test, y_pred))

    ## voting的结果比单个分类器好
    LogisticRegression 0.864
    RandomForestClassifier 0.896
    SVC 0.896
    VotingClassifier 0.912
Read more »

Scala-part4

Posted on 2020-06-20 Edited on 2020-12-06 In Scala

类

继承

java.lang.Object类是JVM中所有实例的根,包括Scala,等价于Scala根类型Any。

AnyRef是Any的子类,是所有可实例化的类型的根。`

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#
scala> class A {
| def hi = "hello from A"
| override def toString = getClass.getName
| }
class A

scala> getClass.getName
val res127: String =

scala> class B extends A
class B

scala> class C extends B {override def hi = "hi C ->" + super.hi}
class C

scala> val hiA = new A().hi
val hiA: String = hello from A

scala> val hiB = new B().hi
val hiB: String = hello from A

scala> val hiC = new C().hi
val hiC: String = hi C ->hello from A
Read more »

决策树

Posted on 2020-06-20 Edited on 2020-12-06 In 机器学习

Update:2020-06-20

last:2019-08-13

CART树用的Gini impurity作为划分指标:在特征满足某个条件时,该指标最小;比如那么用这个特征条件在此处进行划分,分为的做节点有58个实例,其三个类别分别是[0,49,5],那么有GINI:$1-(0/54)^2-(49/54)^2 -(5/54)^2 = 0.168$

Read more »

逻辑与线性回归

Posted on 2020-06-16 Edited on 2020-12-06 In 机器学习

update:2020-06-16

last:2019-08-16

逻辑回归模型

一、定义:逻辑回归模型是用输入$x$的线性函数对输出$Y$的对数几率进行建模的模型,二项逻辑回归的形式为:

  • 其中$w=(w^{(1)},w^{(2)},\dots,w^{(n)},b)^T$ , $x=(x^{(1)},x^{(2)},\dots,x^{(n)},1)^T$.

  • 其中,一个事件的几率是该事件发生与不发生的概率之比,设事件发生的概率是$p$,那么该事件的几率是$\frac{p}{1-p}$,对数几率是$\log\frac{p}{1-p}$.

Read more »
<1234…9>
Zheng Chu

Zheng Chu

90 posts
20 categories
25 tags
GitHub 简书 CSDN E-Mail
© 2021 Zheng Chu
Powered by Hexo v4.2.1
|
Theme – NexT.Pisces v7.3.0
|