コード例 #1
0
def select_baseline(df_pos_normalized: pd.DataFrame,
                    model: tf.keras.Sequential,
                    min_p: float = 0.85,
                    max_count: int = 100):
    """Selects the representative subsamnple that will be used as baselines.

  Based on Proposition 3 (Baseline Set for Anomaly Detection) of
  Interpretable, Multidimensional, Multimodal Anomaly Detection with Negative
  Sampling (Sipple 2020).

  Args:
    df_pos_normalized: data frame of the normalized positive sample.
    model: classifier model from NS-NN.
    min_p: minimum class score to be be considered as a baseline normal.
    max_count: maximum number of reference points to be selected.

  Returns:
    data frame of the normalized baseline and the maximum conf score
  """
    x = np.float32(np.matrix(df_pos_normalized))
    y_hat = model.predict(x, verbose=1, steps=1)
    df_pos_normalized[_CLASS_PROB_LABEL] = y_hat
    high_scoring_predictions = df_pos_normalized[
        df_pos_normalized[_CLASS_PROB_LABEL] >= min_p]
    high_scoring_predictions = high_scoring_predictions.sort_values(
        by=_CLASS_PROB_LABEL, ascending=False)
    high_scoring_predictions = high_scoring_predictions.drop(
        columns=[_CLASS_PROB_LABEL])
    return high_scoring_predictions[:max_count], float(max(y_hat))
コード例 #2
0
 def __evaluate_model(self, model: tf.keras.Sequential, x_test: np.ndarray,
                      y_test: np.ndarray) -> None:
     print('[INFO] evaluating network')
     predictions = model.predict(x=x_test, batch_size=1024)
     print(
         classification_report(y_test,
                               predictions.round(),
                               target_names=['Male', 'Female']))
コード例 #3
0
ファイル: TensorFlowDemo.py プロジェクト: FoVNull/NLPDemo_py
def discernHeadline(model: tf.keras.Sequential, tokenizer: Tokenizer):
    # 预测一个实例
    headline = [
        "granny starting to fear spiders in the garden might be real",
        "teh weather today is bright and sunny"
    ]

    seq = tokenizer.texts_to_sequences(headline)
    padded = pad_sequences(seq, maxlen=100, padding="post", truncating="post")

    print(model.predict(padded))
コード例 #4
0
def display_predictions(chosen_file: str, trained_model: tf.keras.Sequential,
                        original_columns_list):
    """
    Fonction qui affiche les 10 premiers resultats comparant la prediction et la realite
    :param chosen_file: chemin du fichier a comparer
    :param trained_model: modele entraine pour afficher les predictions realisees
    :param original_columns_list: nom des colonnes dans la DF avant nettoyage des donnees
    :return: rien du tout
    """
    df_test = pd.read_pickle(
        chosen_file)  # predictions sur le fichier d'origine pour comparer
    df_test.columns = original_columns_list
    df_test.set_index("MachineIdentifier", inplace=True)
    df_test = cleaning_df(df_test)
    predictions = trained_model.predict(df_test.iloc[:, :-1])
    for i in range(0, 10):
        print("predicted infection: {:.2%} | actual outcome : {}".format(
            predictions[i][0], df_test.iloc[i, -1]))
コード例 #5
0
def predict_monthly_payment(principal: float, interest_rate: float,
                            number_of_payments: float,
                            model: tf.keras.Sequential) -> float:
    return model.predict([(principal, interest_rate, number_of_payments)
                          ])[0][0]