Skip to content

Instantly share code, notes, and snippets.

@iandewancker
Created August 29, 2017 22:58
Show Gist options
  • Save iandewancker/9f86267e54ee6342ee58fd84fac1ba87 to your computer and use it in GitHub Desktop.
Save iandewancker/9f86267e54ee6342ee58fd84fac1ba87 to your computer and use it in GitHub Desktop.
X_test = np.vstack([test_x1, test_x2, test_x3, test_x4, test_x5, test_x6])
y_test = np.array([1.0, 1.0, 1.0, 1.0, -1.0, -1.0])
clf.model.coef_ = clf.model.coef_.reshape(1,clf.model.coef_.shape[0])
# hack to set the classes
try:
clf.model.fit([],[0,1])
except:
pass
# gradient update step simulated
alpha = 0.00125
w_u = clf.model.coef_.flatten()
b_u = clf.model.intercept_
for idx in xrange(X_test.shape[0]):
w_u = w_u - Log.dloss(Log(),clf.model.decision_function(X_test[idx]),y_test[idx])*X_test[idx]*alpha
b_u = b_u - Log.dloss(Log(),clf.model.decision_function(X_test[idx]),y_test[idx])*alpha
clf2 = LogisticRegression()
clf2.coef_ = w_u.reshape(1,w_u.shape[0])
clf2.intercept_ = b_u
try:
clf2.fit([],[0,1])
except:
pass
print "NEW", clf2.predict_proba(X_test)
print "OLD", clf.model.predict_proba(X_test)
print "NEW", clf2.predict(X_test)
print "OLD", clf.model.predict(X_test)
print "NEW", clf2.coef_, clf2.intercept_
print "OLD",clf.model.coef_, clf.model.intercept_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment