sklearn 細節 —— SGDClassifier、Perceptron(分類模型)

Inside_Zhang發表於2015-11-26
  • 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))
      

相關文章