Skip to content

Commit

Permalink
Merge pull request #44 from TeamHG-Memex/set-random-state-more
Browse files Browse the repository at this point in the history
Set random state more
  • Loading branch information
kmike authored Nov 2, 2016
2 parents 223279e + ea2fd3c commit f9ae971
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions tests/test_lime_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_fit_proba():
print(y_pred, mae)

# fit on probabilities
clf2 = LogisticRegression(C=10)
clf2 = LogisticRegression(C=10, random_state=42)
fit_proba(clf2, X, y_proba, expand_factor=200)
y_pred2 = clf2.predict_proba(X)[:,1]
mae2 = mean_absolute_error(y_proba[:,1], y_pred2)
Expand All @@ -43,7 +43,7 @@ def test_fit_proba():

# let's get 3th example really right
sample_weight = np.array([0.1, 0.1, 0.1, 10.0, 0.1])
clf3 = LogisticRegression(C=10)
clf3 = LogisticRegression(C=10, random_state=42)
fit_proba(clf3, X, y_proba, expand_factor=200, sample_weight=sample_weight)
y_pred3 = clf3.predict_proba(X)[:,1]
print(y_pred3)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sklearn_explain_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_explain_linear(newsgroups_train, clf):
[Lars()],
[Lasso(random_state=42)],
[LinearRegression()],
[LinearSVR()],
[LinearSVR(random_state=42)],
[Ridge(random_state=42)],
[RidgeCV()],
[SGDRegressor(random_state=42)],
Expand Down
30 changes: 15 additions & 15 deletions tests/test_sklearn_explain_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def check_newsgroups_explanation_linear(clf, vec, target_names):
assert 'atheists' in pos

pos, neg = _top('talk.religion.misc')
assert 'jesus' in pos
assert 'jesus' in pos or 'christians' in pos

for expl in [expl_text, expl_html]:
assert 'space' in expl
Expand All @@ -68,15 +68,15 @@ def check_newsgroups_explanation_linear(clf, vec, target_names):


@pytest.mark.parametrize(['clf'], [
[LogisticRegression()],
[LogisticRegression(multi_class='multinomial', solver='lbfgs')],
[LogisticRegression(fit_intercept=False)],
[LogisticRegressionCV()],
[LogisticRegression(random_state=42)],
[LogisticRegression(random_state=42, multi_class='multinomial', solver='lbfgs')],
[LogisticRegression(random_state=42, fit_intercept=False)],
[LogisticRegressionCV(random_state=42)],
[SGDClassifier(random_state=42)],
[SGDClassifier(loss='log', random_state=42)],
[PassiveAggressiveClassifier()],
[Perceptron()],
[LinearSVC()],
[SGDClassifier(random_state=42, loss='log')],
[PassiveAggressiveClassifier(random_state=42)],
[Perceptron(random_state=42)],
[LinearSVC(random_state=42)],
])
def test_explain_linear(newsgroups_train, clf):
docs, y, target_names = newsgroups_train
Expand All @@ -89,10 +89,10 @@ def test_explain_linear(newsgroups_train, clf):


@pytest.mark.parametrize(['clf'], [
[LogisticRegression()],
[LogisticRegression(fit_intercept=False)],
[LogisticRegression(random_state=42)],
[LogisticRegression(random_state=42, fit_intercept=False)],
[SGDClassifier(random_state=42)],
[LinearSVC()],
[LinearSVC(random_state=42)],
])
def test_explain_linear_hashed(newsgroups_train, clf):
docs, y, target_names = newsgroups_train
Expand Down Expand Up @@ -160,7 +160,7 @@ def top_pos_neg(classes, key, class_name):
def test_explain_linear_tuple_top(newsgroups_train):
docs, y, target_names = newsgroups_train
vec = TfidfVectorizer()
clf = LogisticRegression()
clf = LogisticRegression(random_state=42)

X = vec.fit_transform(docs)
clf.fit(X, y)
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_explain_random_forest(newsgroups_train, clf):


def test_explain_empty(newsgroups_train):
clf = LogisticRegression(C=0.01, penalty='l1')
clf = LogisticRegression(C=0.01, penalty='l1', random_state=42)
docs, y, target_names = newsgroups_train
vec = TfidfVectorizer()

Expand Down Expand Up @@ -242,7 +242,7 @@ def test_unsupported():
[RidgeCV()],
[SGDRegressor(random_state=42)],
[LinearRegression()],
[LinearSVR()],
[LinearSVR(random_state=42)],
])
def test_explain_linear_regression(boston_train, clf):
X, y, feature_names = boston_train
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sklearn_vectorizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _without_weighted_spans(res):


def test_explain_linear_dense():
clf = LogisticRegression()
clf = LogisticRegression(random_state=42)
data = [{'day': 'mon', 'moon': 'full'},
{'day': 'tue', 'moon': 'rising'},
{'day': 'tue', 'moon': 'rising'},
Expand Down

0 comments on commit f9ae971

Please sign in to comment.