8. Fine-Tuning Classification Algorithms
Activity 8.01: Implementing Different Classification Algorithms
Solution:
- Import the logistic regression library:
from sklearn.linear_model import LogisticRegression
- Fit the model:
clf_logistic = LogisticRegression(random_state=0,solver='lbfgs')\
.fit(X_train[top7_features], y_train)
clf_logistic
The preceding code will give the following output:
LogisticRegression(random_state=0)
- Score the model:
clf_logistic.score(X_test[top7_features], y_test)
You will get the following output: 0.7454031117397454.
This shows that the logistic regression model is getting an accuracy of 74.5%, which is a mediocre accuracy but serves as a good estimate of the minimum accuracy you can expect.
- Import the svm library:
from sklearn import svm
- Scale the training and testing data as follows:
from sklearn.preprocessing import MinMaxScaler
scaling = MinMaxScaler...