Escolar Documentos
Profissional Documentos
Cultura Documentos
log_reg = LogisticRegression(penalty="l2")
log_reg.fit(X,y)
X_new = np.linspace(0,3,1000).reshape(-1,1)
y_proba = log_reg.predict_proba(X_new)
Virginica Probability
softmax_reg = LogisticRegression(multi_class="multinomial",
solver="lbfgs", C=5)
softmax_reg.fit(X,y)
pred = softmax_reg.predict(X_test)
Classifying with Logistic Regression
3. Naive Bayes
Perhaps the simplest of all the models discussed in this article, we make
it now to Naive Bayes. Naive Bayes is great for the small amount of data
necessary to estimate parameters. Naive Bayes applies Bayes’ theorem
and is called naive because of the assumption of conditional
independence between each feature. In this example I apply Gaussian
Naive Bayes:
clf = GaussianNB()
clf.fit(X,y)
X_new = np.linspace(0,3,1000).reshape(-1,1)
y_proba = clf.predict_proba(X_new)
clf = GaussianNB()
clf.fit(X,y)
pred = clf.predict(X)
Classifying with Naive Bayes
4. Random Forest
Random Forest is a popular ensemble model used quite frequently. You
can see ensemble models popping up all over the place, especially in
Kaggle competitions. Random forest works by fitting decision tree
classifiers on subsamples of the dataset. It then averages classification
performance to garner superior accuracy whilst avoiding overfitting.
We set n_estimators to 100 which sets the number of trees in the forest
to 100. Max depth sets the maximum depth of the tree.
5. AdaBoost
Another popular ensemble model…AdaBoost works to fit many
classifiers on the dataset with different weights for incorrectly classified
instances. AdaBoost training selects the features known to increase the
classification power of the model. This of course acts as dimension
reduction, which is a plus as long as classification capabilities are
preserved.
clf = AdaBoostClassifier(n_estimators=100)
clf.fit(X,y)
X_new = np.linspace(0,3,1000).reshape(-1,1)
y_proba = clf.predict_proba(X_new)
clf = AdaBoostClassifier(n_estimators=100)
clf.fit(X,y)
pred = clf.predict(X)
Classifying with AdaBoost
Congrats
Hooray! You made it to the end. Now it’s your job to ask questions and
try to understand these models on a deeper level. In the next article I
will dive into the pros and cons of each model. Until next time…