Search code examples
machine-learningsvmdata-miningpca

can I use PCA for dimensionality reduction and then use its o/p for one class SVM classifier in python


I want to use PCA for dimensionality reduction and then use its o/p for one class SVM classifier in python. My training data set is of the order 16000x60. Also how to map principal component to original column to use it in SVM or can I use principal component directly?


Solution

  • It is unclear what the problem is and what did you try already. Of course you can. You can either add PCA output to your original set or just use the output as a single feature. I encourage you to use sklearn pipelines.

    Simple example:

    from sklearn import decomposition, datasets
    from sklearn.pipeline import Pipeline
    from sklearn import svm
    
    svc = svm.SVC()
    pca = decomposition.PCA()
    
    pipe = Pipeline(steps=[('pca', pca), ('svc', svc)])
    
    digits = datasets.load_digits()
    X_digits = digits.data
    y_digits = digits.target
    
    pipe.fit(X_digits, y_digits)
    print(pipe.score(X_digits,y_digits))