Created
July 31, 2018 05:32
-
-
Save otaviomguerra/8a5faf7be4b53011144de11765e8bf15 to your computer and use it in GitHub Desktop.
A machine Learning pipeline example using Imputer and SVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import the Imputer module | |
from sklearn.preprocessing import Imputer | |
from sklearn.svm import SVC | |
# Setup the Imputation transformer: imp | |
imp = Imputer(missing_values='NaN', strategy='most_frequent', axis=0) | |
# Instantiate the SVC classifier: clf | |
clf = SVC() | |
# Setup the pipeline with the required steps: steps | |
steps = [('imputation', imp), | |
('SVM', clf)] | |
# Create the pipeline: pipeline | |
pipeline = Pipeline(steps) | |
# Create training and test sets | |
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.30, random_state=42) | |
# Fit the pipeline to the train set | |
pipeline.fit(X_train, y_train) | |
# Predict the labels of the test set | |
y_pred = pipeline.predict(X_test) | |
# Compute metrics | |
print(classification_report(y_test, y_pred)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment