HPI_tpot_pipeline.py 987 B

1234567891011121314151617181920212223
  1. import numpy as np
  2. from sklearn.ensemble import VotingClassifier
  3. from sklearn.linear_model import LogisticRegression
  4. from sklearn.model_selection import train_test_split
  5. from sklearn.pipeline import make_pipeline, make_union
  6. from sklearn.preprocessing import FunctionTransformer, MaxAbsScaler, MinMaxScaler
  7. # NOTE: Make sure that the class is labeled 'class' in the data file
  8. tpot_data = np.recfromcsv('PATH/TO/DATA/FILE', delimiter='COLUMN_SEPARATOR', dtype=np.float64)
  9. features = np.delete(tpot_data.view(np.float64).reshape(tpot_data.size, -1), tpot_data.dtype.names.index('class'), axis=1)
  10. training_features, testing_features, training_classes, testing_classes = \
  11. train_test_split(features, tpot_data['class'], random_state=42)
  12. exported_pipeline = make_pipeline(
  13. MaxAbsScaler(),
  14. MinMaxScaler(),
  15. LogisticRegression(C=49.0, dual=True, penalty="l2")
  16. )
  17. exported_pipeline.fit(training_features, training_classes)
  18. results = exported_pipeline.predict(testing_features)