a bit crazy

a bit crazy

Posted on
Dec 7, 2022 06:47 PM
With lots of sadness in mind… the time doesn stop, so I have to go for my works
I’m involved in a awesome course by fun-mooc.fr (in English of course) and the question was:
Use a DummyClassifier such that the resulting classifier will always predict the class ' >50K'. What is the accuracy score on the test set? Repeat the experiment by always predicting the class ' <=50K'.
and I did
from sklearn.dummy import DummyClassifier dummymodel = DummyClassifier(strategy='prior') _ = dummymodel.fit(data_train,target_train) # for checking if any False is available (false referse to ' >50K') for i in (dummymodel.predict(data_test) == ' <=50K'): if i == False: print("there is a false") print("This model predicts only ' <=50K'") print("Score based on train data is\t{}".format(dummymodel.score(data_train, target_train))) print("Score based on test data is\t{}".format(dummymodel.score(data_test, target_test))) print("===============") dummymodel2 = DummyClassifier(strategy='constant', constant=' >50K') _ = dummymodel2.fit(data_train,target_train) # for checking if any False is available (false referse to ' >50K') n = 0 for i in (dummymodel2.predict(data_test) == ' >50K'): if i == False: n+=1 print("n is %d" %(n)) print("This model predicts only ' >50K'") print("Score based on train data is\t{}".format(dummymodel2.score(data_train, target_train))) print("Score based on test data is\t{}".format(dummymodel2.score(data_test, target_test))) print("======== \n" "Let do some tweak \n" "Sum of scores for train data is \t %f \n" "Sum of scores for test data is \t %f" %(dummymodel2.score(data_train, target_train)+dummymodel.score(data_train, target_train), dummymodel2.score(data_test, target_test)+dummymodel.score(data_test, target_test)))
😐