【问题标题】:Use Bagging Classifier with a support vector machine model将 Bagging 分类器与支持向量机模型一起使用
【发布时间】:2019-04-26 13:19:51
【问题描述】:

当我尝试执行时

svm = SVC(gamma='auto',random_state = 42,probability=True)
BaggingClassifier(base_estimator=svm, n_estimators=31, random_state=314).fit(X,y)

它无限期地运行。是命令导致计算以非常慢的速度发生还是我做错了?

【问题讨论】:

    标签: python machine-learning scikit-learn classification svm


    【解决方案1】:

    您正确使用它。 SVC 超级慢。以下是您可以检查的方法:

    from sklearn.svm import LinearSVC
    from sklearn.ensemble import BaggingClassifier
    import hasy_tools  # pip install hasy_tools
    
    # Load and preprocess data
    data = hasy_tools.load_data()
    X = data['x_train']
    X = hasy_tools.preprocess(X)
    X = X.reshape(len(X), -1)
    y = data['y_train']
    
    # Reduce dataset
    dataset_size = 100
    X = X[:dataset_size]
    y = y[:dataset_size]
    
    # Define model
    svm = LinearSVC(random_state=42)
    model = BaggingClassifier(base_estimator=svm, n_estimators=31, random_state=314)
    
    # Fit
    model.fit(X, y)
    

    有关why SVC is slow 的更多详细信息,请访问 datascience.SE。

    【讨论】:

      猜你喜欢
      • 2011-07-01
      • 2018-06-15
      • 2011-10-15
      • 2013-08-31
      • 2016-02-20
      • 1970-01-01
      • 2017-08-18
      • 2018-05-28
      • 2020-10-10
      相关资源
      最近更新 更多