3rd Code
3rd Code
3rd Code
### Question: Create a binary classifier for the digit 5 using stochastic
### gradient descent for only 5 iterations
### then obtain the cross validation accuracy using 3 folds
y_train_5 = (y_train == 5)
y_test_5 = (y_test == 5)
12:
### Question: obtain prediction using cross validation with 3 folds for
### X_train as X and y_train_5 as Y
### then obtain the confusion matrix for this prediction
### then obtain the confusion matrix for the perfect prediction
### then obtain precision, recall and f1 score
y_train_perfect_predictions = y_train_5
print('confusion_matrix_perfect')
print(confusion_matrix(y_train_5, y_train_5))
14:
### Question: obtain prediction scores using cross validation with 3 folds
### for X_train as X and y_train_5 as Y
### then obtain the precision recall curve then plot it
16:
### Question: obtain prediction scores using cross validation with 3 folds
### for X_train as X and y_train_5 as Y
### then obtain the roc curve then plot it
### then obtain the roc area under the curve score
17:
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train.astype(np.float64))
print(cross_val_score(sgd_clf, X_train_scaled, y_train, cv=3, scoring="accuracy"))
18:
### Question: obtain the cross validation predictions for the stochastic gradient
### descent multiclass classifier using 3 folds such that X_train_scaled
### as X and y_train as Y
### then obtain the confusion matrix and print it
19:
### Question: create a random noise with max value of 100 for images
### with size 28*28 then add them to X_train and X_test
### then create a KNN classifier such that X_train with
### noise as X and X_train without noise as Y
### then do prediction for X_test of index 5500
### and plot it
knn_clf = KNeighborsClassifier()
knn_clf.fit(X_train_mod, y_train_mod)
clean_digit = knn_clf.predict([X_test_mod[5500]])
plot_digit(clean_digit)