def test_default_template_no_feature_importances(self): #Load a model model = joblib.load( os.path.join(models_path, 'classifier_without_feature_importances_model.pkl')) #Load y_true y_true = joblib.load( os.path.join(models_path, 'classifier_without_feature_importances_y_true.pkl')) #Load y_pred y_pred = joblib.load( os.path.join(models_path, 'classifier_without_feature_importances_y_pred.pkl')) #Load y_score y_score = joblib.load( os.path.join(models_path, 'classifier_without_feature_importances_y_score.pkl')) #Load X X = joblib.load( os.path.join(models_path, 'classifier_without_feature_importances_x.pkl')) #Generate feature list feature_list = range(X.shape[1]) #FIND A BETTER WAY TO DO THIS #Generate target names target_names = range(len(set(y_true))) #FIND A BETTER WAY #Report name name = 'test_report_without_feature_importances' rg = ReportGenerator() report = rg.generate_report(model=model, y_true=y_true, y_pred=y_pred, y_score=y_score, feature_list=feature_list, target_names=target_names, name=name) #Load dummy report dummy_report_file = open( os.path.join( models_path, 'classiffier_without_feature_importances_report.html')) dummy_report = dummy_report_file.read() #Compare report self.assertEqual(report, dummy_report)
def test_default_template_no_feature_importances(self): #Load a model model = joblib.load(os.path.join(models_path,'classifier_without_feature_importances_model.pkl')) #Load y_true y_true = joblib.load(os.path.join(models_path,'classifier_without_feature_importances_y_true.pkl')) #Load y_pred y_pred = joblib.load(os.path.join(models_path,'classifier_without_feature_importances_y_pred.pkl')) #Load y_score y_score = joblib.load(os.path.join(models_path,'classifier_without_feature_importances_y_score.pkl')) #Load X X = joblib.load(os.path.join(models_path,'classifier_without_feature_importances_x.pkl')) #Generate feature list feature_list = range(X.shape[1]) #FIND A BETTER WAY TO DO THIS #Generate target names target_names = range(len(set(y_true))) #FIND A BETTER WAY #Report name name = 'test_report_without_feature_importances' rg = ReportGenerator() report = rg.generate_report(model=model, y_true=y_true, y_pred=y_pred, y_score=y_score, feature_list=feature_list, target_names=target_names, name=name) #Load dummy report dummy_report_file = open(os.path.join(models_path, 'classiffier_without_feature_importances_report.html')) dummy_report = dummy_report_file.read() #Compare report self.assertEqual(report, dummy_report)
svc.fit(X_train, y_train) y_true = y_test y_pred = svc.predict(X_test) y_score = svc.predict_proba(X_test) #Pickle model joblib.dump(svc, os.path.join(models_path, 'classifier_without_feature_importances_model.pkl')) #Pickle y_true joblib.dump(y_true, os.path.join(models_path, 'classifier_without_feature_importances_y_true.pkl')) #Pickle y_pred joblib.dump(y_pred, os.path.join(models_path, 'classifier_without_feature_importances_y_pred.pkl')) #Pickle y_score joblib.dump(y_score, os.path.join(models_path, 'classifier_without_feature_importances_y_score.pkl')) #Pickle X joblib.dump(X, os.path.join(models_path, 'classifier_without_feature_importances_x.pkl')) #Generate feature list feature_list = range(X.shape[1]) #Generate target names target_names = range(len(set(y))) #Name name = 'test_report_without_feature_importances' #Generate report rg = ReportGenerator() report = rg.generate_report(model=svc, y_true=y_true, y_pred=y_pred, y_score=y_score, feature_list=feature_list, target_names=target_names, name=name) #Save report to file report_file = open(os.path.join(models_path, 'classiffier_without_feature_importances_report.html'), 'w') report_file.write(report) report_file.close()
forest.fit(X_train, y_train) y_true = y_test y_pred = forest.predict(X_test) y_score = forest.predict_proba(X_test) #Pickle model joblib.dump(forest, os.path.join(models_path, 'classifier_with_feature_importances_model.pkl')) #Pickle y_true joblib.dump(y_true, os.path.join(models_path, 'classifier_with_feature_importances_y_true.pkl')) #Pickle y_pred joblib.dump(y_pred, os.path.join(models_path, 'classifier_with_feature_importances_y_pred.pkl')) #Pickle y_score joblib.dump(y_score, os.path.join(models_path, 'classifier_with_feature_importances_y_score.pkl')) #Pickle X joblib.dump(X, os.path.join(models_path, 'classifier_with_feature_importances_x.pkl')) #Generate feature list feature_list = range(X.shape[1]) #Generate target names target_names = range(len(set(y))) #Name name = 'test_report' #Generate report rg = ReportGenerator() report = rg.generate_report(model=forest, y_true=y_true, y_pred=y_pred, y_score=y_score, feature_list=feature_list, target_names=target_names, name=name) #Save report to file report_file = open(os.path.join(models_path, 'classiffier_with_feature_importances_report.html'), 'w') report_file.write(report) report_file.close()