本文整理匯總了Python中sklearn.preprocessing.StandardScaler.todense方法的典型用法代碼示例。如果您正苦於以下問題:Python StandardScaler.todense方法的具體用法?Python StandardScaler.todense怎麽用?Python StandardScaler.todense使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sklearn.preprocessing.StandardScaler
的用法示例。
在下文中一共展示了StandardScaler.todense方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from sklearn.preprocessing import StandardScaler [as 別名]
# 或者: from sklearn.preprocessing.StandardScaler import todense [as 別名]
def main():
(X_all,y,feature_names) = Prepare_2(model=8).fit()
lentrain = len(y)
print "X_all:",X_all.shape,"y:",lentrain,"features:",len(feature_names) ,feature_names
print "X_all[0]:", [(k,X_all[0,i]) for (i,k )in enumerate(feature_names)]
from sklearn.preprocessing import StandardScaler
X_all = StandardScaler().fit_transform(X_all.todense())
X = X_all[:lentrain]
clf1 = lm.LogisticRegression(penalty='l1', dual=False, tol=0.00001,
C=0.05, fit_intercept=True, intercept_scaling=1.0,
class_weight=None, random_state=123)
clf2 = RandomForestClassifier(n_estimators=200, max_depth=24,
n_jobs=-1, random_state=1, verbose=0)
clf3 = GradientBoostingClassifier(n_estimators=100, max_depth=16,
random_state=1, verbose=2, subsample=0.9)
clf4 = svm.SVC(probability=True)
clf5 = KNeighborsClassifier(n_neighbors=5)
clf6 = SGDClassifier(alpha=0.0001, class_weight=None, epsilon=0.1, eta0=0.0,
fit_intercept=True, l1_ratio=0.15, learning_rate='optimal',
loss='hinge', n_iter=50, n_jobs=1, penalty='elasticnet', power_t=0.5,
random_state=None, rho=None, shuffle=False, verbose=0,
warm_start=False)
clf7 = lm.LogisticRegression(penalty='l1', dual=False, tol=0.0001,
C=1, fit_intercept=True, intercept_scaling=1.0,
class_weight=None, random_state=123)
clf8 = svm.SVC(C=1, kernel='linear', probability=True)
clf9 = svm.LinearSVC(C=0.010, loss='l2', penalty='l1', dual=False)
clf = clf1
"""
selector = RFECVp(clf2,clf2, step=50, cv=4, scoring="roc_auc", verbose=2)
selector = selector.fit(X, y)
clf = selector
"""
rd = Pipeline([
#("selector", SelectPercentile(chi2, percentile=90)),
#("selector", SelectPercentile(f_classif, percentile=50)),
#("selector", lm.RandomizedLogisticRegression(C=1, random_state=1, verbose=1)),
#("pca", PCA(n_components='mle')),
#("pca", PCA(n_components=500)),
#("svd", TruncatedSVD(n_components=200, random_state=1 )),
#("lasso",svm.LinearSVC(C=0.01, penalty="l1", dual=False)),
("est", clf)
])
if True:
cv_run(rd, X, y)
return
else:
print "Prepare submission.."
print "training on full data"
rd.fit(X,y)
X_test = X_all[lentrain:]
pred = rd.predict_proba(X_test)[:,1]
testfile = pd.read_csv('../data/test.tsv', sep="\t", na_values=['?'], index_col=1)
pred_df = pd.DataFrame(pred, index=testfile.index, columns=['label'])
submname = 'submission_%s' % (datetime.datetime.today().strftime("%Y%m%d_%H%M%S"),)
#print submname
pred_df.to_csv('../data/%s.csv' % submname)
print "%s file created.." % submname