8000 [MRG] Fixed warnings for DataDimensionalityWarning and decision function by amueller · Pull Request #5395 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG] Fixed warnings for DataDimensionalityWarning and decision function #5395

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

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 sklearn/linear_model/tests/test_least_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def test_multitarget():
for estimator in (linear_model.LassoLars(), linear_model.Lars()):
estimator.fit(X, Y)
Y_pred = estimator.predict(X)
Y_dec = estimator.decision_function(X)
Y_dec = assert_warns(DeprecationWarning, estimator.decision_function, X)
assert_array_almost_equal(Y_pred, Y_dec)
alphas, active, coef, path = (estimator.alphas_, estimator.active_,
estimator.coef_, estimator.coef_path_)
Expand Down
2 changes: 1 addition & 1 deletion sklearn/linear_model/tests/test_sgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ def test_partial_fit(self):
clf.partial_fit(X[:third], Y[:third])
assert_equal(clf.coef_.shape, (X.shape[1], ))
assert_equal(clf.intercept_.shape, (1,))
assert_equal(clf.decision_function([[0, 0]]).shape, (1, ))
assert_equal(clf.predict([[0, 0]]).shape, (1, ))
id1 = id(clf.coef_.data)

clf.partial_fit(X[third:], Y[third:])
Expand Down
27 changes: 14 additions & 13 deletions sklearn/neighbors/tests/test_approximate.py

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_neighbors_accuracy_with_n_candidates():

for i, n_candidates in enumerate(n_candidates_values):
lshf = LSHForest(n_candidates=n_candidates)
lshf.fit(X)
ignore_warnings(lshf.fit)(X)
for j in range(n_iter):
query = X[rng.randint(0, n_samples)].reshape(1, -1)

Expand Down Expand Up @@ -74,7 +74,7 @@ def test_neighbors_accuracy_with_n_estimators():

for i, t in enumerate(n_estimators):
lshf = LSHForest(n_candidates=500, n_estimators=t)
lshf.fit(X)
ignore_warnings(lshf.fit)(X)
for j in range(n_iter):
query = X[rng.randint(0, n_samples)].reshape(1, -1)
neighbors = lshf.kneighbors(query, n_neighbors=n_points,
Expand Down Expand Up @@ -111,7 +111,7 @@ def test_kneighbors():
# Test unfitted estimator
assert_raises(ValueError, lshf.kneighbors, X[0])

lshf.fit(X)
ignore_warnings(lshf.fit)(X)

for i in range(n_iter):
n_neighbors = rng.randint(0, n_samples)
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_radius_neighbors():
# Test unfitted estimator
assert_raises(ValueError, lshf.radius_neighbors, X[0])

lshf.fit(X)
ignore_warnings(lshf.fit)(X)

for i in range(n_iter):
# Select a random point in the dataset as the query
Expand Down Expand Up @@ -218,6 +218,7 @@ def test_radius_neighbors():
sorted_dists_approx)))


@ignore_warnings
def test_radius_neighbors_boundary_handling():
X = [[0.999, 0.001], [0.5, 0.5], [0, 1.], [-1., 0.001]]
n_points = len(X)
Expand Down Expand Up @@ -286,7 +287,7 @@ def test_distances():
X = rng.rand(n_samples, n_features)

lshf = LSHForest()
lshf.fit(X)
ignore_warnings(lshf.fit)(X)

for i in range(n_iter):
n_neighbors = rng.randint(0, n_samples)
Expand All @@ -312,7 +313,7 @@ def test_fit():
X = rng.rand(n_samples, n_features)

lshf = LSHForest(n_estimators=n_estimators)
lshf.fit(X)
ignore_warnings(lshf.fit)(X)

# _input_array = X
assert_array_equal(X, lshf._fit_X)
Expand Down Expand Up @@ -343,16 +344,16 @@ def test_partial_fit():
lshf = LSHForest()

# Test unfitted estimator
lshf.partial_fit(X)
ignore_warnings(lshf.partial_fit)(X)
assert_array_equal(X, lshf._fit_X)

lshf.fit(X)
ignore_warnings(lshf.fit)(X)

# Insert wrong dimension
assert_raises(ValueError, lshf.partial_fit,
np.random.randn(n_samples_partial_fit, n_features - 1))

lshf.partial_fit(X_partial_fit)
ignore_warnings(lshf.partial_fit)(X_partial_fit)

# size of _input_array = samples + 1 after insertion
assert_equal(lshf._fit_X.shape[0],
Expand All @@ -379,7 +380,7 @@ def test_hash_functions():

lshf = LSHForest(n_estimators=n_estimators,
random_state=rng.randint(0, np.iinfo(np.int32).max))
lshf.fit(X)
ignore_warnings(lshf.fit)(X)

hash_functions = []
for i in range(n_estimators):
Expand All @@ -405,7 +406,7 @@ def test_candidates():

# For zero candidates
lshf = LSHForest(min_hash_match=32)
lshf.fit(X_train)
ignore_warnings(lshf.fit)(X_train)

message = ("Number of candidates is not sufficient to retrieve"
" %i neighbors with"
Expand All @@ -419,7 +420,7 @@ def test_candidates():

# For candidates less than n_neighbors
lshf = LSHForest(min_hash_match=31)
lshf.fit(X_train)
ignore_warnings(lshf.fit)(X_train)
message = ("Number of candidates is not sufficient to retrieve"
" %i neighbors with"
Expand All @@ -441,7 +442,7 @@ def test_graphs():
for n_samples in n_samples_sizes:
X = rng.rand(n_samples, n_features)
lshf = LSHForest(min_hash_match=0)
lshf.fit(X)
ignore_warnings(lshf.fit)(X)

kneighbors_graph = lshf.kneighbors_graph(X)
radius_neighbors_graph = lshf.radius_neighbors_graph(X)
Expand Down
2 changes: 1 addition & 1 deletion sklearn/svm/tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def check_svm_model_equal(dense_svm, sparse_svm, X_train, y_train, X_test):
msg = "cannot use sparse input in 'OneClassSVM' trained on dense data"
else:
assert_array_almost_equal(dense_svm.predict_proba(X_test_dense),
sparse_svm.predict_proba(X_test), 4)
sparse_svm.predict_proba(X_test), 4)
msg = "cannot use sparse input in 'SVC' trained on dense data"
if sparse.isspmatrix(X_test):
assert_raise_message(ValueError, msg, dense_svm.predict, X_test)
Expand Down
9 changes: 4 additions & 5 deletions sklearn/svm/tests/test_svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,9 @@ def test_decision_function_shape():
assert_equal(dec.shape, (len(X_train), 10))


@ignore_warnings
def test_svr_decision_function():
def test_svr_predict():
# Test SVR's decision_function
# Sanity check, test that decision_function implemented in python
# Sanity check, test that predict implemented in python
# returns the same as the one in libsvm

X = iris.data
Expand All @@ -367,14 +366,14 @@ def test_svr_decision_function():
reg = svm.SVR(kernel='linear', C=0.1).fit(X, y)

dec = np.dot(X, reg.coef_.T) + reg.intercept_
assert_array_almost_equal(dec.r 607E avel(), reg.decision_function(X).ravel())
assert_array_almost_equal(dec.ravel(), reg.predict(X).ravel())

# rbf kernel
reg = svm.SVR(kernel='rbf', gamma=1).fit(X, y)

rbfs = rbf_kernel(X, reg.support_vectors_, gamma=reg.gamma)
dec = np.dot(rbfs, reg.dual_coef_.T) + reg.intercept_
assert_array_almost_equal(dec.ravel(), reg.decision_function(X).ravel())
assert_array_almost_equal(dec.ravel(), reg.predict(X).ravel())


def test_weight():
Expand Down
0