Tensorfow2复习--LowerAPI
Tensorfow2复习--RNN
Python-Trick
精通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.
CodeWar
EnsembleLearning
[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
33from 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
Scala-part4
类
继承
java.lang.Object
类是JVM中所有实例的根,包括Scala,等价于Scala根类型Any
。
AnyRef
是Any
的子类,是所有可实例化的类型的根。`
1 | # |
决策树
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$