本文整理汇总了Python中eden.graph.Vectorizer.set_params方法的典型用法代码示例。如果您正苦于以下问题:Python Vectorizer.set_params方法的具体用法?Python Vectorizer.set_params怎么用?Python Vectorizer.set_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eden.graph.Vectorizer
的用法示例。
在下文中一共展示了Vectorizer.set_params方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TransformerWrapper
# 需要导入模块: from eden.graph import Vectorizer [as 别名]
# 或者: from eden.graph.Vectorizer import set_params [as 别名]
class TransformerWrapper(BaseEstimator, ClassifierMixin):
"""TransformerWrapper."""
def __init__(self, program=None):
"""Construct."""
self.program = program
self.vectorizer = Vectorizer()
self.params_vectorize = dict()
def set_params(self, **params):
"""Set the parameters of this estimator.
The method.
Returns
-------
self
"""
# finds parameters for the vectorizer as those that contain "__"
params_vectorizer = dict()
params_clusterer = dict()
for param in params:
if "vectorizer__" in param:
key = param.split('__')[1]
val = params[param]
params_vectorizer[key] = val
elif "vectorize__" in param:
key = param.split('__')[1]
val = params[param]
self.params_vectorize[key] = val
else:
params_clusterer[param] = params[param]
self.program.set_params(**params_clusterer)
self.vectorizer.set_params(**params_vectorizer)
return self
def fit(self, graphs):
"""fit."""
try:
self.program.fit(graphs)
return self
except Exception as e:
logger.debug('Failed iteration. Reason: %s' % e)
logger.debug('Exception', exc_info=True)
def transform(self, graphs):
"""predict."""
try:
for graph in graphs:
transformed_graph = self._transform(graph)
yield transformed_graph
except Exception as e:
logger.debug('Failed iteration. Reason: %s' % e)
logger.debug('Exception', exc_info=True)
def _transform(self, graph):
return graph
示例2: OrdererWrapper
# 需要导入模块: from eden.graph import Vectorizer [as 别名]
# 或者: from eden.graph.Vectorizer import set_params [as 别名]
class OrdererWrapper(BaseEstimator, ClassifierMixin):
"""Orderer."""
def __init__(self, program=None):
"""Construct."""
self.program = program
self.vectorizer = Vectorizer()
self.params_vectorize = dict()
def set_params(self, **params):
"""Set the parameters of this estimator.
The method.
Returns
-------
self
"""
# finds parameters for the vectorizer as those that contain "__"
params_vectorizer = dict()
params_orderer = dict()
for param in params:
if "vectorizer__" in param:
key = param.split('__')[1]
val = params[param]
params_vectorizer[key] = val
elif "vectorize__" in param:
key = param.split('__')[1]
val = params[param]
self.params_vectorize[key] = val
else:
params_orderer[param] = params[param]
self.program.set_params(**params_orderer)
self.vectorizer.set_params(**params_vectorizer)
return self
def decision_function(self, graphs):
"""decision_function."""
try:
graphs, graphs_ = tee(graphs)
data_matrix = vectorize(graphs_,
vectorizer=self.vectorizer,
**self.params_vectorize)
scores = self.program.decision_function(data_matrix)
return scores
except Exception as e:
logger.debug('Failed iteration. Reason: %s' % e)
logger.debug('Exception', exc_info=True)
示例3: RegressorWrapper
# 需要导入模块: from eden.graph import Vectorizer [as 别名]
# 或者: from eden.graph.Vectorizer import set_params [as 别名]
class RegressorWrapper(BaseEstimator, RegressorMixin):
"""Regressor."""
def __init__(self,
program=SGDRegressor(average=True, shuffle=True)):
"""Construct."""
self.program = program
self.vectorizer = Vectorizer()
self.params_vectorize = dict()
def set_params(self, **params):
"""Set the parameters of this estimator.
The method.
Returns
-------
self
"""
# finds parameters for the vectorizer as those that contain "__"
params_vectorizer = dict()
params_clusterer = dict()
for param in params:
if "vectorizer__" in param:
key = param.split('__')[1]
val = params[param]
params_vectorizer[key] = val
elif "vectorize__" in param:
key = param.split('__')[1]
val = params[param]
self.params_vectorize[key] = val
else:
params_clusterer[param] = params[param]
self.program.set_params(**params_clusterer)
self.vectorizer.set_params(**params_vectorizer)
return self
def fit(self, graphs):
"""fit."""
try:
graphs, graphs_ = tee(graphs)
data_matrix = vectorize(graphs_,
vectorizer=self.vectorizer,
**self.params_vectorize)
y = self._extract_targets(graphs)
self.program = self.program.fit(data_matrix, y)
return self
except Exception as e:
logger.debug('Failed iteration. Reason: %s' % e)
logger.debug('Exception', exc_info=True)
def predict(self, graphs):
"""predict."""
try:
graphs, graphs_ = tee(graphs)
data_matrix = vectorize(graphs_,
vectorizer=self.vectorizer,
**self.params_vectorize)
predictions = self.program.predict(data_matrix)
for prediction, graph in izip(predictions, graphs):
graph.graph['prediction'] = prediction
graph.graph['score'] = prediction
yield graph
except Exception as e:
logger.debug('Failed iteration. Reason: %s' % e)
logger.debug('Exception', exc_info=True)
def _extract_targets(self, graphs):
y = []
for graph in graphs:
if graph.graph.get('target', None) is not None:
y.append(graph.graph['target'])
else:
raise Exception('Missing the attribute "target" \
in graph dictionary!')
y = np.ravel(y)
return y
示例4: ClassifierWrapper
# 需要导入模块: from eden.graph import Vectorizer [as 别名]
# 或者: from eden.graph.Vectorizer import set_params [as 别名]
class ClassifierWrapper(BaseEstimator, ClassifierMixin):
"""Classifier."""
def __init__(self,
program=SGDClassifier(average=True,
class_weight='balanced',
shuffle=True)):
"""Construct."""
self.program = program
self.vectorizer = Vectorizer()
self.params_vectorize = dict()
def set_params(self, **params):
"""Set the parameters of this estimator.
The method.
Returns
-------
self
"""
# finds parameters for the vectorizer as those that contain "__"
params_vectorizer = dict()
params_clusterer = dict()
for param in params:
if "vectorizer__" in param:
key = param.split('__')[1]
val = params[param]
params_vectorizer[key] = val
elif "vectorize__" in param:
key = param.split('__')[1]
val = params[param]
self.params_vectorize[key] = val
else:
params_clusterer[param] = params[param]
self.program.set_params(**params_clusterer)
self.vectorizer.set_params(**params_vectorizer)
return self
def fit(self, graphs):
"""fit."""
try:
graphs, graphs_ = tee(graphs)
data_matrix = vectorize(graphs_,
vectorizer=self.vectorizer,
**self.params_vectorize)
y = self._extract_targets(graphs)
# manage case for single class learning
if len(set(y)) == 1:
# make negative data matrix
negative_data_matrix = data_matrix.multiply(-1)
# make targets
y = list(y)
y_neg = [-1] * len(y)
# concatenate elements
data_matrix = vstack(
[data_matrix, negative_data_matrix], format="csr")
y = y + y_neg
y = np.ravel(y)
self.program = self.program.fit(data_matrix, y)
return self
except Exception as e:
logger.debug('Failed iteration. Reason: %s' % e)
logger.debug('Exception', exc_info=True)
def predict(self, graphs):
"""predict."""
try:
graphs, graphs_ = tee(graphs)
data_matrix = vectorize(graphs_,
vectorizer=self.vectorizer,
**self.params_vectorize)
predictions = self.program.predict(data_matrix)
scores = self.program.decision_function(data_matrix)
for score, prediction, graph in izip(scores, predictions, graphs):
graph.graph['prediction'] = prediction
graph.graph['score'] = score
yield graph
except Exception as e:
logger.debug('Failed iteration. Reason: %s' % e)
logger.debug('Exception', exc_info=True)
def _extract_targets(self, graphs):
y = []
for graph in graphs:
if graph.graph.get('target', None) is not None:
y.append(graph.graph['target'])
else:
raise Exception('Missing the attribute "target" \
in graph dictionary!')
y = np.ravel(y)
return y