Ontwikkel een machinelearning-pijplijn

IoT-gegevens analyseren in Python

Matthias Voppichler

IT Developer

Pijplijn

  • Transformatie
    • Conversie
    • Schalen
  • Estimator
    • Model
IoT-gegevens analyseren in Python

Maak een pijplijn

from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline

# Initialize Objects sc = StandardScaler() logreg = LogisticRegression()
# Create pipeline pl = Pipeline([ ("scale", sc), ("logreg", logreg) ])
IoT-gegevens analyseren in Python

Inspecteer pijplijn

pl
Pipeline(memory=None,
         steps=[('scale', StandardScaler(copy=True, with_mean=True, with_std=True)), 
                ('logreg', <class 'sklearn.linear_model.logistic.LogisticRegression'>)])
pl.fit(X_train, y_train)

print(pl.predict(X_test))
[0 0 1 1 0 1 1 0 0]
IoT-gegevens analyseren in Python

Model opslaan

import pickle

with Path("pipeline_model.pkl").open("bw") as f: pickle.dump(pl, f)
IoT-gegevens analyseren in Python

Model laden

import pickle
with Path("pipeline_model.pkl").open('br') as f:
    pl = pickle.load(f)

pl
Pipeline(memory=None,
     steps=[('scale', StandardScaler(copy=True, with_mean=True, with_std=True)), 
             ('logreg', LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
          intercept_scaling=1, max_iter=100, multi_class='warn', n_jobs=None, penalty='l2', 
          random_state=None, solver='warn', tol=0.0001, verbose=0, warm_start=False))])

Let op

Pak nooit pickles uit van onbetrouwbare bronnen; dit kan kwaadaardige code uitvoeren.

IoT-gegevens analyseren in Python

Laten we oefenen!

IoT-gegevens analyseren in Python

Preparing Video For Download...