Supervised learning पाइपलाइंस

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

Dr. Chris Anagnostopoulos

Honorary Associate Professor

Labeled डेटा

  • Feature वैरिएबल (शॉर्टहैंड: X)
  • Labels या class (शॉर्टहैंड: y)
credit_scoring.head(4)
  checking_status  duration  ...  foreign_worker class
0            '<0'         6  ...             yes  good
1      '0<=X<200'        48  ...             yes   bad
2   'no checking'        12  ...             yes  good
3            '<0'        42  ...             yes  good
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

Feature engineering

  • ज़्यादातर classifiers को numeric features चाहिए
  • String कॉलम्स को numbers में बदलना होगा

sklearn.preprocessing के LabelEncoder से preprocess करें:

le = LabelEncoder()
le.fit_transform(credit_scoring['checking_status'])[:4]
array([1, 0, 3, 1])
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

Model fitting

  • .fit(features, labels)
  • .predict(features)
features, labels = credit_scoring.drop('class', 1), credit_scoring['class']

model_nb = GaussianNB() model_nb.fit(features, labels) model_nb.predict(features.head(5))
['good' 'bad' 'good' 'bad' 'good']

पहले 5 उदाहरणों पर 60% accuracy.

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

Model selection

  • .fit() दिए गए मॉडल के पैरामीटर optimize करता है
  • दूसरे मॉडलों का क्या?

पहले पाँच डेटा पॉइंट्स पर AdaBoostClassifier ने GaussianNB से बेहतर किया:

model_ab = AdaBoostClassifier()
model_ab.fit(features, labels)
model_ab.predict(features.head(5))
numpy.array(labels[0:5])
['good' 'bad' 'good' 'good' 'bad']
['good' 'bad' 'good' 'good' 'bad']
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

Performance assessment

बड़ा sample size $\Rightarrow$ बेहतर accuracy estimate:

from sklearn.metrics import accuracy_score
accuracy_score(labels, model_nb.predict(features)) # naive bayes
0.706
accuracy_score(labels, model_ab.predict(features)) # adaboost
0.802

इस calculation में क्या गलत है?

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

Overfitting और data splitting

Overfitting: जिस डेटा पर मॉडल train होता है, उस पर वह हमेशा अनदेखे डेटा से बेहतर करेगा.

X_train, y_train पर train करें, X_test, y_test पर accuracy आंके:

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

GaussianNB().fit(X_train, y_train).predict(X_test)
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

एक मानक supervised learning वर्कफ़्लो जो feature engineering से शुरू होकर train/test में data splitting, फिर model assessment और model selection तक जाता है. वास्तविक समस्याओं में यह standard pipeline कभी-कभी काफ़ी नहीं होती.

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

तो, यह कोर्स किस बारे में है?

  1. अपनी पाइपलाइन को scalable तरीकों से tune करना.
  2. डोमेन विशेषज्ञों को जोड़कर predictions प्रासंगिक रखना.
  3. समय के साथ मॉडल का प्रदर्शन बना रहे, यह सुनिश्चित करना.
  4. जब labels कम हों तब भी मॉडल fit करना.
Python में मशीन लर्निंग वर्कफ़्लो डिज़ाइन करना

क्या आप mortgage संकट रोक सकते थे?

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

Preparing Video For Download...