-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtpot_firstTry_pipeline.py
30 lines (27 loc) · 1.44 KB
/
tpot_firstTry_pipeline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import numpy as np
import pandas as pd
from sklearn.feature_selection import SelectFwe, f_classif
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import BernoulliNB, GaussianNB
from sklearn.pipeline import make_pipeline, make_union
from sklearn.preprocessing import PolynomialFeatures
from sklearn.svm import LinearSVC
from tpot.builtins import StackingEstimator
# NOTE: Make sure that the class is labeled 'target' in the data file
tpot_data = pd.read_csv('PATH/TO/DATA/FILE', sep='COLUMN_SEPARATOR', dtype=np.float64)
features = tpot_data.drop('target', axis=1).values
training_features, testing_features, training_target, testing_target = \
train_test_split(features, tpot_data['target'].values, random_state=42)
# Score on the training set was:-0.5439756576220649
exported_pipeline = make_pipeline(
StackingEstimator(estimator=GaussianNB()),
StackingEstimator(estimator=GaussianNB()),
StackingEstimator(estimator=BernoulliNB(alpha=1.0, fit_prior=True)),
PolynomialFeatures(degree=2, include_bias=False, interaction_only=False),
StackingEstimator(estimator=LinearSVC(C=0.01, dual=False, loss="squared_hinge", penalty="l2", tol=0.001)),
SelectFwe(score_func=f_classif, alpha=0.042),
LogisticRegression(C=0.01, dual=False, penalty="l2")
)
exported_pipeline.fit(training_features, training_target)
results = exported_pipeline.predict(testing_features)