本文整理汇总了Python中sklearn.linear_model.SGDClassifier.fit_transform方法的典型用法代码示例。如果您正苦于以下问题:Python SGDClassifier.fit_transform方法的具体用法?Python SGDClassifier.fit_transform怎么用?Python SGDClassifier.fit_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.linear_model.SGDClassifier
的用法示例。
在下文中一共展示了SGDClassifier.fit_transform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: feature_selection
# 需要导入模块: from sklearn.linear_model import SGDClassifier [as 别名]
# 或者: from sklearn.linear_model.SGDClassifier import fit_transform [as 别名]
def feature_selection(data_matrix, target):
from sklearn.feature_selection import RFECV
from sklearn.linear_model import SGDClassifier
estimator = SGDClassifier(average=True, shuffle=True, penalty='elasticnet')
# perform feature rescaling with elastic penalty
data_matrix = estimator.fit_transform(data_matrix, target)
# perform recursive feature elimination
selector = RFECV(estimator, step=0.1, cv=10)
data_matrix = selector.fit_transform(data_matrix, target)
return data_matrix
示例2: xrange
# 需要导入模块: from sklearn.linear_model import SGDClassifier [as 别名]
# 或者: from sklearn.linear_model.SGDClassifier import fit_transform [as 别名]
selected_terms = []
for i in xrange(25):
print i
clusterer = KMeans(n_clusters=np.random.randint(5,10), init='random', max_iter=200, n_init=1)
print 'clustering'
clusterer.fit(X_vec)
#TODO: Check within/between cluster metrics, ignore weak clusters
print 'selecting features'
X_sel = selector.fit_transform(X_vec, clusterer.labels_)
print 'classifying'
classifier.fit_transform(X_sel, clusterer.labels_)
print 'extracting terms'
fnames = vectorizer.get_feature_names()
feature_terms = [ fnames[i] for i in selector.get_support(True) ]
for c in range(clusterer.n_clusters):
c_f = sorted(zip(classifier.coef_[c,:], feature_terms), reverse=True)
for w,t in c_f[:5]:
if w > 0:
selected_terms.append(t)
else:
break
counter = collections.Counter(selected_terms)
counter.most_common(50)