本文整理汇总了Python中LogisticRegression.LogisticRegression.score方法的典型用法代码示例。如果您正苦于以下问题:Python LogisticRegression.score方法的具体用法?Python LogisticRegression.score怎么用?Python LogisticRegression.score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogisticRegression.LogisticRegression
的用法示例。
在下文中一共展示了LogisticRegression.score方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cross_validation
# 需要导入模块: from LogisticRegression import LogisticRegression [as 别名]
# 或者: from LogisticRegression.LogisticRegression import score [as 别名]
def cross_validation(X,y,bsize, fold, eta, solver="SGD", wdecay=0):
from sklearn.cross_validation import StratifiedKFold
from LogisticRegression import LogisticRegression
scores=[]
skf = StratifiedKFold( y, fold)
for train_index, test_index in skf:
X_train, X_test, y_train, y_test = X[train_index,:], X[test_index,:], y[train_index], y[test_index]
lr = LogisticRegression(learning=solver,weight_decay=wdecay,eta_0=eta, batch_size=bsize)
lr.fit(X_train,y_train)
scores.append(lr.score(X_test,y_test))
return np.mean(scores)
示例2: read_data
# 需要导入模块: from LogisticRegression import LogisticRegression [as 别名]
# 或者: from LogisticRegression.LogisticRegression import score [as 别名]
shuffle_examples, normalize_fetures= True , True
X_train,y_train = read_data("./Data/train",normalize_fetures,shuffle_examples)
X_test,y_test = read_data("./Data/test",normalize_fetures)
if doGridSearch:
if regularized:
eta, weight, cv_acc= RLR_SGD_grid(X_train, y_train,bsize)
else:
eta, cv_acc= LR_SGD_grid(X_train, y_train, bsize)
weight=0
else:
eta=0.01
if regularized:
weight=0.01
else:
weight=0
solver="SGD"
# lr = LogisticRegression(learning=solver)
lr = LogisticRegression(learning=solver, eta_0=eta, weight_decay=weight, max_epoch=10, batch_size=bsize)
lr.fit(X_train,y_train)
sklr = linear_model.LogisticRegression(penalty="l2",C=10000.).fit(X_train,y_train)
test_acc=lr.score(X_test,y_test)
runname=str(bsize)+('','R')[regularized]+'LR'
print solver, runname, "Test Accuracy:", test_acc
with open('out','a') as f:
f.write('{0}\t\t{1}\t\t{2}\n'.format(runname, cv_acc, test_acc))
# print "SkitLearn Accuracy:",sklr.score(X_test,y_test)