美文网首页
不同分类器比较

不同分类器比较

作者: overad | 来源:发表于2021-01-20 17:52 被阅读0次

针对不同的分类器的效果比较:

不同分类器效果比较.png
import warnings 
warnings.filterwarnings('ignore')

import numpy as np
np.random.seed(0)

import matplotlib.pyplot as plt

from sklearn.datasets import make_classification
from sklearn.naive_bayes import GaussianNB
from sklearn.linear_model import LogisticRegression
from sklearn.svm import LinearSVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.calibration import calibration_curve

n_samples = 10000
n_features = 20
n_informative = 2
n_redundant = 2

X,y = make_classification(n_samples=n_samples,n_features=n_features,
                          n_informative=n_informative,n_redundant=n_redundant)

train_samples = 100 

X_train = X[:train_samples]
X_test = X[train_samples:]
y_train = y[:train_samples]
y_test = y[train_samples:]

lr = LogisticRegression()
svc = LinearSVC(C=1.0)
rfc = RandomForestClassifier()
gnb = GaussianNB()

plt.figure(figsize=(10, 10))
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan=2)
ax2 = plt.subplot2grid((3, 1), (2, 0))

ax1.plot([0, 1], [0, 1], "k:", label="Perfectly calibrated")

for clf, name in [(lr, 'Logistic'),
                  (gnb, 'Naive Bayes'),
                  (svc, 'Support Vector Classification'),
                  (rfc, 'Random Forest')]:
    clf.fit(X_train, y_train)
    if hasattr(clf, "predict_proba"):
        prob_pos = clf.predict_proba(X_test)[:, 1]
    else:  # use decision function
        prob_pos = clf.decision_function(X_test)
        prob_pos = (prob_pos - prob_pos.min()) / (prob_pos.max() - prob_pos.min())
    fraction_of_positives, mean_predicted_value = calibration_curve(y_test, prob_pos, n_bins=10)

    ax1.plot(mean_predicted_value, fraction_of_positives, "s-",
             label="%s" % (name, ))

    ax2.hist(prob_pos, range=(0, 1), bins=10, label=name,
             histtype="step", lw=2)

ax1.set_ylabel("Fraction of positives")
ax1.set_ylim([-0.05, 1.05])
ax1.legend(loc="lower right")
ax1.set_title('Calibration plots  (reliability curve)')

ax2.set_xlabel("Mean predicted value")
ax2.set_ylabel("Count")
ax2.legend(loc="upper center", ncol=2)

plt.tight_layout()
plt.show()

相关文章

  • 不同分类器比较

    针对不同的分类器的效果比较:

  • 损失函数

    线性分类器简介 线性评分函数 阐明线性分类器 损失函数多分类SVMsoftmax分类器SVM和softmax的比较...

  • 1-1 除尘器的分类和性能

    1、 除尘器的分类 除尘器的不同分类方法可以分为许多类型,用于不同粉尘和不同条件。 1) 按除尘作用力原理情况分类...

  • 比较分类器的方法

    考虑一对分类模型Ma和Mb。假设Ma在包含30个记录的检验集上的准确率达到85%,而Mb在包含5000个记录的不同...

  • (15)监督学习-分类问题-集成学习

    集成多个弱分类器来改善分类器的泛化性能和鲁棒性。多个弱分类器线性组合成一个强分类器。可以是不同算法的集成,也可...

  • Softmax分类器

    Softmax分类器可以理解为逻辑回归分类器面对多个分类的一般化归纳。公式: SVM和Softmax的比较:   ...

  • 2.1.1.3朴素贝叶斯

    模型介绍:与基于假设的模型(线性分类器和支持向量机分类器)不同的是,朴素贝叶斯分类器的构造基础是贝叶斯理论。朴素贝...

  • 机器学习之分类器

    0、分类器热身,NextStep比较懒,直接看图 分类分类,先分解再分类,比如,疾病分类模型先将病情的表现信息进行...

  • 分服务器内存

    系统需要处理相同逻辑但某种类型不同业务.比如商品,根据不同的分类,加载缓存到不同的服务器,一个服务器只处理某个分类...

  • NSArray数组

    sorted分类 / comparator比较器 / descriptors描述符 / ascend上升 /...

网友评论

      本文标题:不同分类器比较

      本文链接:https://www.haomeiwen.com/subject/deokzktx.html