本文整理汇总了Python中sklearn.linear_model.SGDClassifier.n_iter方法的典型用法代码示例。如果您正苦于以下问题:Python SGDClassifier.n_iter方法的具体用法?Python SGDClassifier.n_iter怎么用?Python SGDClassifier.n_iter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.linear_model.SGDClassifier
的用法示例。
在下文中一共展示了SGDClassifier.n_iter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stochastic_gradient_descent
# 需要导入模块: from sklearn.linear_model import SGDClassifier [as 别名]
# 或者: from sklearn.linear_model.SGDClassifier import n_iter [as 别名]
print "cost = "+str(cost)
return history, costs, preds
# In[28]:
iters = 10 # set number of iterations
history, cost, preds = stochastic_gradient_descent(np.array(Feature_vector), np.array(Y_Target), iters)
theta = history[-1]
# In[29]:
from sklearn.linear_model import SGDClassifier
clf = SGDClassifier(loss="hinge", penalty="l2")
clf.n_iter = 5
clf.fit(np.array(Feature_vector), np.array(Y_Target))
# In[30]:
print "pridicted = " + str(clf.predict([Feature_vector[0]]))
print "Actual = " + str(Y_Target[0])
# In[31]:
lf = SGDClassifier(loss="log")
lf.n_iter = 5000
lf.fit(np.array(Feature_vector), np.array(Y_Target))
lf.predict_proba(Feature_vector[0])
示例2: MultinomialNB
# 需要导入模块: from sklearn.linear_model import SGDClassifier [as 别名]
# 或者: from sklearn.linear_model.SGDClassifier import n_iter [as 别名]
# initialize NB classifier
#clf = MultinomialNB()
#clf = BernoulliNB()
#clf.class_prior =[0.041175856307435255,0.9588241436925647]
#clf = svm.SVC()
#clf.cache_size = 4000
#clf.n_jobs = -1
#clf.C = .1
clf = SGDClassifier()
clf.n_jobs = -1
clf.C =1
clf.alpha = .00000001
clf.n_iter = 10000
#clf = DecisionTreeClassifier()
#clf.max_depth = 3
#scores = cross_validation.cross_val_score(clf, feat_vecs, labels, cv=10,scoring='recall')
#print scores
#set_trace()
def mp(t,k=None):
# set_trace()
trainI,testI = t
if k:
ch2 = SelectKBest(chi2, k=k)
best = ch2.fit(feat_vecs[trainI], labels[trainI]) #do chi2 fit on train data
test_feats = best.transform(feat_vecs[testI]).toarray() # test data reduced to same k features