मॉडल डिप्लॉयमेंट

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

Dr. Chris Anagnostopoulos

Honorary Associate Professor

एक मॉडल पाइपलाइन ऑब्जेक्ट जिसमें feature selection, model selection, model tuning और model fitting शामिल हैं, उसे प्रोडक्शन पाइपलाइन में पुश किया जाता है जो fitted पाइपलाइन से prediction करती है.

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

अपने मॉडल को सीरियलाइज़ करना

क्लासिफायर को फ़ाइल में सहेजें:

import pickle
clf = RandomForestClassifier().fit(X_train, y_train)
with open('model.pkl', 'wb') as file:
    pickle.dump(clf, file=file)

इसे फिर फ़ाइल से लोड करें:

with open('model.pkl', 'rb') as file:
    clf2 = pickle.load(file)
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

अपनी पाइपलाइन को सीरियलाइज़ करना

डेवलपमेंट एन्वायरनमेंट:

vt = SelectKBest(f_classif).fit(
    X_train, y_train)
clf = RandomForestClassifier().fit(
    vt.transform(X_train), y_train)
with open('vt.pkl', 'wb') as file: 
     pickle.dump(vt)
with open('clf.pkl', 'wb') as file: 
     pickle.dump(clf)

एक वर्कफ़्लो जहाँ feature selector ऑब्जेक्ट और fitted मॉडल दोनों को अलग-अलग प्रोडक्शन में पुश करना पड़ता है.

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

अपनी पाइपलाइन को सीरियलाइज़ करना

प्रोडक्शन एन्वायरनमेंट:

with open('vt.pkl', 'rb') as file: 
    vt = pickle.load(vt)
with open('clf.pkl', 'rb') as file: 
    clf = pickle.load(clf)
clf.predict(vt.transform(X_new))

एक वर्कफ़्लो जहाँ feature selector ऑब्जेक्ट और fitted मॉडल दोनों को अलग-अलग प्रोडक्शन में पुश करना पड़ता है.

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

अपनी पाइपलाइन को सीरियलाइज़ करना

डेवलपमेंट एन्वायरनमेंट:

pipe = Pipeline([
    ('fs', SelectKBest(f_classif)), 
    ('clf', RandomForestClassifier())
])
params = dict(fs__k=[2, 3, 4],
    clf__max_depth=[5, 10, 20])
gs = GridSearchCV(pipe, params)
gs = gs.fit(X_train, y_train)

with open('pipe.pkl', 'wb') as file: pickle.dump(gs, file)

एक ऑप्टिमाइज़्ड वर्कफ़्लो जहाँ feature selection और model fitting दोनों एक ही pipeline ऑब्जेक्ट में हैं.

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

अपनी पाइपलाइन को सीरियलाइज़ करना

प्रोडक्शन एन्वायरनमेंट:

with open('pipe.pkl', 'rb') as file:
   gs = pickle.dump(gs, file)
gs.predict(X_test)

एक ऑप्टिमाइज़्ड वर्कफ़्लो जहाँ feature selection और model fitting दोनों एक ही pipeline ऑब्जेक्ट में हैं.

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

कस्टम फीचर ट्रांसफ़ॉर्मेशन

   checking_status  duration       ...        own_telephone  foreign_worker
0                1         6       ...                    1               1
1                0        48       ...                    0               1
def negate_second_column(X):
    Z = X.copy()
    Z[:,1] = -Z[:,1]
    return Z
pipe = Pipeline([('ft', FunctionTransformer(negate_second_column)), 
    ('clf', RandomForestClassifier())])
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

प्रोडक्शन के लिए तैयार!

Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

Preparing Video For Download...