from sklearn.model_selection import train_test_split,cross_val_predict,StratifiedKFold from sklearn.preprocessing import StandardScaler from sklearn.metrics import classification_report,roc_auc_score,roc_curve from imblearn.pipeline import Pipeline as imbPipe from imblearn.over_sampling import SMOTE from sklearn.ensemble import VotingClassifier from sklearn.linear_model import LogisticRegression, SGDClassifier from sklearn.tree import DecisionTreeClassifier from sklearn.svm import LinearSVC, SVC from sklearn.neighbors import KNeighborsClassifier X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, shuffle=True, stratify = y) dct = DecisionTreeClassifier(random_state=42) sgd = SGDClassifier(random_state=42) log = LogisticRegression(random_state=42) svm_rbf = SVC(kernel="rbf", random_state=42) svm_lin = LinearSVC(loss="hinge") knn=KNeighborsClassifier() kfold = StratifiedKFold(n_splits=4, shuffle=True, random_state=42) Voting_pipeline = imbPipe([ ("scaler", StandardScaler()), ("smote", SMOTE(random_state=42,n_jobs=-1)), ("voting", VotingClassifier(estimators=[("dct", dct), ("sgd", sgd), ("svm_rbf", svm_rbf), ("smv_lin", svm_lin), ("knn",knn), ("log", log)],voting="hard",n_jobs=-1)) ]) y_pred = cross_val_predict(Voting_pipeline, X_train, y_train, cv = kfold) print(classification_report(y_train, y_pred))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter