本文整理汇总了Python中lightning.classification.FistaClassifier.alpha方法的典型用法代码示例。如果您正苦于以下问题:Python FistaClassifier.alpha方法的具体用法?Python FistaClassifier.alpha怎么用?Python FistaClassifier.alpha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lightning.classification.FistaClassifier
的用法示例。
在下文中一共展示了FistaClassifier.alpha方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rank
# 需要导入模块: from lightning.classification import FistaClassifier [as 别名]
# 或者: from lightning.classification.FistaClassifier import alpha [as 别名]
def rank(M, eps=1e-9):
U, s, V = svd(M, full_matrices=False)
return np.sum(s > eps)
bunch = fetch_20newsgroups_vectorized(subset="train")
X_train = bunch.data
y_train = bunch.target
# Reduces dimensionality to make the example faster
ch2 = SelectKBest(chi2, k=5000)
X_train = ch2.fit_transform(X_train, y_train)
bunch = fetch_20newsgroups_vectorized(subset="test")
X_test = bunch.data
y_test = bunch.target
X_test = ch2.transform(X_test)
clf = FistaClassifier(C=1.0 / X_train.shape[0],
max_iter=200,
penalty="trace",
multiclass=True)
for alpha in (1e-3, 1e-2, 0.1, 0.2, 0.3):
print("alpha=", alpha)
clf.alpha = alpha
clf.fit(X_train, y_train)
print(clf.score(X_test, y_test))
print(rank(clf.coef_))