Exemple #1
0
 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)
Exemple #3
0
X = np.c_[X, random_state.randn(n_samples, 200 * n_features)]

# shuffle and split training and test sets
X_train, X_test, y_train, y_test = train_test_split(X,
                                                    y,
                                                    test_size=.5,
                                                    random_state=0)

# Learn to predict each class against the other
classifier = OneVsRestClassifier(
    svm.SVC(kernel='linear', probability=True, random_state=random_state))
classifier = classifier.fit(X_train, y_train)

y_pred = classifier.predict(X_test)
y_score = classifier.decision_function(X_test)

feature_list = range(4)
target_names = ['setosa', 'versicolor', 'virginica']

#Create a trained model instance
tm = ClassificationModelResults(classifier,
                                y_test,
                                y_pred,
                                y_score,
                                feature_list,
                                target_names,
                                model_name='sample_model_report')

#Generate report
report_gen = ReportGenerator(savepath='/Users/Edu/Desktop')
report_gen(tm)
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()
Exemple #5
0
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()