sklearn 细节 —— SGDClassifier、Perceptron(分类模型)

  • Perceptron

    iris_data = load_iris()
    X = iris_data.data[:, (2, 3)]
    y = (iris_data.target == 0).astype(np.int)
    perp_clf = Perceptron()
    perp_clf.fit(X, y)
    
    print(perp_clf.predict(np.asarray([2, .5]).reshape(-1, 2)))
    

1. 线性分类

  • SGDClassifier 基本训练:

    from sklearn.linear_model import SGDClassifier
    clf = SGDClassifier()
    clf.fit(train_data, train_labels)
    train_predications = clf.predict(train_data)
    
    • 混淆矩阵:

      from sklern.metrics import classification_report, confusion_matrix
      print('', classification_report(train_labels, train_predications))
      print('', confusion_matrix(train_labels, train_predications))
      

你可能感兴趣的:(sklearn 细节 —— SGDClassifier、Perceptron(分类模型))