当前位置: 首页>>代码示例>>Python>>正文


Python LogisticRegression.fit方法代码示例

本文整理汇总了Python中LogisticRegression.LogisticRegression.fit方法的典型用法代码示例。如果您正苦于以下问题:Python LogisticRegression.fit方法的具体用法?Python LogisticRegression.fit怎么用?Python LogisticRegression.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LogisticRegression.LogisticRegression的用法示例。


在下文中一共展示了LogisticRegression.fit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cross_validation

# 需要导入模块: from LogisticRegression import LogisticRegression [as 别名]
# 或者: from LogisticRegression.LogisticRegression import fit [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)
开发者ID:esayyari,项目名称:Projects,代码行数:13,代码来源:readdata.py

示例2: GaussianGenerativeModel

# 需要导入模块: from LogisticRegression import LogisticRegression [as 别名]
# 或者: from LogisticRegression.LogisticRegression import fit [as 别名]
# Do not change anything below this line!!
# -----------------------------------------------------------------

# Read from file and extract X and Y
df = pd.read_csv("fruit.csv")
X = df[['width', 'height']].values
Y = (df['fruit'] - 1).values

nb1 = GaussianGenerativeModel(isSharedCovariance=False)
nb1.fit(X,Y)
nb1.test_insample()
print "Gaussian model with separate covariance: in-sample error rate %.1f%%" % (nb1.insample_err * 100.0 )
nb1.visualize("generative_result_separate_covariances.png",show_charts=True)

nb2 = GaussianGenerativeModel(isSharedCovariance=True)
nb2.fit(X,Y)
nb2.test_insample()
print "Gaussian model with shared covariance: in-sample error rate %.1f%%" % (nb2.insample_err * 100.0 )
nb2.visualize("generative_result_shared_covariances.png",show_charts=True)

for idx,lamda in enumerate([ 0.0001, 0.001, 0.01, 0.1, 1, 0 ]):
    lr = LogisticRegression(eta=eta, lambda_parameter=lamda)
    lr.fit(X,Y)
    lr.test_insample()
    print "Logistic regression with lambda %.5f, in-sample error rate %.1f%%" % ( lamda, lr.insample_err * 100.0 )
    lr.visualize('logistic_regression_result_%d.png' % idx, show_charts=True)



开发者ID:weiyialanchen,项目名称:cs181-s16,代码行数:28,代码来源:problem3.py

示例3: read_data

# 需要导入模块: from LogisticRegression import LogisticRegression [as 别名]
# 或者: from LogisticRegression.LogisticRegression import fit [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)

开发者ID:esayyari,项目名称:Projects,代码行数:31,代码来源:runLogisticRegression.py


注:本文中的LogisticRegression.LogisticRegression.fit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。