Question
pelase finsih this in accordance with MNIST dataset class gen_classifier(object): def __init__(self, x_train, x_test, y_train, y_test): self.x_train=x_train self.x_test=x_test self.y_train=y_train self.y_test=y_test self.seed = 1000 # For
pelase finsih this in accordance with MNIST dataset
class gen_classifier(object):
def __init__(self, x_train, x_test, y_train, y_test):
self.x_train=x_train
self.x_test=x_test
self.y_train=y_train
self.y_test=y_test
self.seed = 1000 # For reproducibility
self.unique_classes= np.unique(y_train)
def fit_decision_tree_classifier(self):
#####
# Add code here to train/fit decision tree on mnist
clf_dt=None
return clf_dt
def fit_random_forest_classifier(self):
#####
# Add code here to train/fit random forest on mnist
clf_rf=None
return clf_rf
def clf_predict(self,trained_clf=None):
### Use your trained classifier to make predictions
### Replace following hard coded lines with your code
y_pred_train = np.zeros(self.y_train.shape)
y_pred_test = np.zeros(self.y_test.shape)
####
return y_pred_train, y_pred_test, self.y_train, self.y_test
def per_class_metrics(self, y_true, y_pred, classifier_name=None, split=None):
TP=[]
TN=[]
Accuracy=[]
Precision=[]
Recall=[]
F1score=[]
Label=[]
for label in self.unique_classes:
# Write code here that calculates the following for current label and assigns the values in variable named = (tp,tn,acc,prec,recall, f1)
###################
# Your code here
# For example, hard coded to 0:
tp = 0
tn= 0
acc = 0
prec = 0
rec = 0
f1= 0
##########################
TP.append(tp)
TN.append(tn)
Accuracy.append(acc)
Precision.append(prec)
Recall.append(rec)
F1score.append(f1)
Label.append(label)
clf_name=classifier_name
text=''
for idx in range(len(Label)):
text += 'For class : {}, Following are the metrics with {} on {} set True Positive : {} True Negative : {} Accuracy : {} Precision : {} Recall : {} F1score : {} '.format(Label[idx],clf_name, split ,TP[idx],TN[idx],Accuracy[idx],Precision[idx],Recall[idx],F1score[idx])
print(text)
def overall_metrics(self, y_true, y_pred,classifier_name=None, split=None):
# Write code here that calculates the following and assigns the values in variable named = (tp,tn,acc,prec,recall, f1)
###################
# Your code here
# For example, hard coded to 0:
tp = 0
tn= 0
acc = 0
prec = 0
rec = 0
f1= 0
##########################
clf_name=classifier_name
text = 'Following are the metrics for {} on {} set: True Positive : {} True Negative : {} Accuracy : {} Precision : {} Recall : {} F1score : {} '.format(clf_name, split ,tp,tn,acc,prec,rec,f1)
print(text)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started