Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for allowing multi-dimensional inputs (ndim > 2) #minor #97

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hiclass/HierarchicalClassifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _pre_fit(self, X, y, sample_weight):

if not self.bert:
self.X_, self.y_ = self._validate_data(
X, y, multi_output=True, accept_sparse="csr"
X, y, multi_output=True, accept_sparse="csr", allow_nd=True
)
else:
self.X_ = np.array(X)
Expand Down
2 changes: 1 addition & 1 deletion hiclass/LocalClassifierPerLevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def predict(self, X):

# Input validation
if not self.bert:
X = check_array(X, accept_sparse="csr")
X = check_array(X, accept_sparse="csr", allow_nd=True, ensure_2d=False)
else:
X = np.array(X)

Expand Down
2 changes: 1 addition & 1 deletion hiclass/LocalClassifierPerNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def predict(self, X):

# Input validation
if not self.bert:
X = check_array(X, accept_sparse="csr")
X = check_array(X, accept_sparse="csr", allow_nd=True, ensure_2d=False)
else:
X = np.array(X)

Expand Down
2 changes: 1 addition & 1 deletion hiclass/LocalClassifierPerParentNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def predict(self, X):

# Input validation
if not self.bert:
X = check_array(X, accept_sparse="csr")
X = check_array(X, accept_sparse="csr", allow_nd=True, ensure_2d=False)
else:
X = np.array(X)

Expand Down
17 changes: 17 additions & 0 deletions tests/test_LocalClassifierPerLevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,20 @@ def test_knn():
check_is_fitted(lcpl)
# predictions = lcpl.predict(X)
# assert_array_equal(y, predictions)


def test_fit_multiple_dim_input():
lcpl = LocalClassifierPerLevel()
X = np.random.rand(1, 275, 3)
y = np.array([["a", "b", "c"]])
lcpl.fit(X, y)
check_is_fitted(lcpl)


def test_predict_multiple_dim_input():
lcpl = LocalClassifierPerLevel()
X = np.random.rand(1, 275, 3)
y = np.array([["a", "b", "c"]])
lcpl.fit(X, y)
predictions = lcpl.predict(X)
assert predictions is not None
17 changes: 17 additions & 0 deletions tests/test_LocalClassifierPerNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,20 @@ def test_knn():
check_is_fitted(lcpn)
# predictions = lcpn.predict(X)
# assert_array_equal(y, predictions)


def test_fit_multiple_dim_input():
lcpn = LocalClassifierPerNode()
X = np.random.rand(1, 275, 3)
y = np.array([["a", "b", "c"]])
lcpn.fit(X, y)
check_is_fitted(lcpn)


def test_predict_multiple_dim_input():
lcpn = LocalClassifierPerNode()
X = np.random.rand(1, 275, 3)
y = np.array([["a", "b", "c"]])
lcpn.fit(X, y)
predictions = lcpn.predict(X)
assert predictions is not None
17 changes: 17 additions & 0 deletions tests/test_LocalClassifierPerParentNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,20 @@ def test_knn():
check_is_fitted(lcppn)
# predictions = lcppn.predict(X)
# assert_array_equal(y, predictions)


def test_fit_multiple_dim_input():
lcppn = LocalClassifierPerParentNode()
X = np.random.rand(1, 275, 3)
y = np.array([["a", "b", "c"]])
lcppn.fit(X, y)
check_is_fitted(lcppn)


def test_predict_multiple_dim_input():
lcppn = LocalClassifierPerParentNode()
X = np.random.rand(1, 275, 3)
y = np.array([["a", "b", "c"]])
lcppn.fit(X, y)
predictions = lcppn.predict(X)
assert predictions is not None
Loading