コード例 #1
0
ファイル: train.py プロジェクト: delbertbeta/ML2018-lab-03
                imageData = np.array(image)
                npd = feature.NPDFeature(imageData)
                features.append(npd.extract())
        AdaBoostClassifier.save(features, 'features.dump')

    features = np.array(features)
    print(features.shape)

    X_train, X_val, y_train, y_val = train_test_split(features,
                                                      y,
                                                      test_size=0.25)

    classifier = AdaBoostClassifier(DecisionTreeClassifier, 5)
    classifier.fit(X_train, y_train)

    score = classifier.predict_scores(X_val, y_val)
    predict = classifier.predict(X_val)

    y_val = np.array(list(map(lambda x: int(x), y_val.reshape(1, -1)[0])))
    predict = np.array(list(map(lambda x: int(x), predict.reshape(1, -1)[0])))

    print(predict)
    print(y_val)

    reportContent = 'score = ' + str(score) + '\n'
    reportContent += classification_report(y_val, predict)

    with open('classifier_report.txt', 'w') as report:
        report.write(reportContent)

    pass
コード例 #2
0
    load_img()
    npd_feature()
    img_features = np.array(img_features)
    img_labels = np.array(img_labels).reshape((-1, 1))
    print(img_features.shape)
    print(img_features)
    X_train, X_val, y_train, y_val = train_test_split(img_features,
                                                      img_labels,
                                                      test_size=0.25)
    print(X_train.shape, X_val.shape, y_train.shape, y_val.shape)

    ada = AdaBoostClassifier(DecisionTreeClassifier, WEAKERS_LIMIT)
    ada.fit(X_train, y_train)

    y_predict = ada.predict(X_val)
    acc = ada.predict_scores(X_val, y_val)

    print(acc)

    y_val = np.array(list(map(lambda x: int(x), y_val.reshape(1, -1)[0])))
    y_predict = np.array(
        list(map(lambda x: int(x),
                 y_predict.reshape(1, -1)[0])))

    print(y_predict)
    print(y_val)

    reportContent = 'Accuracy = ' + str(acc) + '\n'
    reportContent += classification_report(y_val, y_predict)

    with open('report.txt', 'w') as report: