def test_predict_proba():
    clf = TimeSeriesForestClassifier(n_estimators=2)
    clf.fit(X, y)
    proba = clf.predict_proba(X)

    assert proba.shape == (X.shape[0], n_classes)
    np.testing.assert_array_equal(np.ones(X.shape[0]), np.sum(proba, axis=1))

    # test single row input
    y_proba = clf.predict_proba(X.iloc[[0], :])
    assert y_proba.shape == (1, n_classes)

    y_pred = clf.predict(X.iloc[[0], :])
    assert y_pred.shape == (1,)
Example #2
0
y_train = pd.Series(y_train.reshape(-1))
y_test = pd.Series(y_test.reshape(-1))


# Timeseries random foreset for every column
for i, col in enumerate(col_names[:2]):
    print(col)

    # Choose one feature
    X_train_step = X_train.iloc[:, [i]]
    X_test_step = X_test.iloc[:, [i]]

    # Time series forest clf
    classifier = TimeSeriesForestClassifier()
    classifier.fit(X_train_step, y_train)
    y_pred = classifier.predict(X_test_step)
    
    # Metrics
    print(f'accuracy_test: {accuracy_score(y_test, y_pred)}')
    print(f"recall_test: {recall_score(y_test, y_pred)}")
    print(f"precisoin_test: {precision_score(y_test, y_pred)}")
    print(f"f1_test: {f1_score(y_test, y_pred)}")



# clf2 = pickle.loads(s)
# clf2.predict(X_test[0:1])


# # KNeighbors Classifier
# clf = KNeighborsTimeSeriesClassifier(n_neighbors=2,