Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version - 0.0.20 #22

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion encexp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
if not '-m' in sys.argv:
from encexp.text_repr import EncExp, EncExpT, SeqTM, TM

__version__ = "0.0.19"
__version__ = "0.0.20"
81 changes: 41 additions & 40 deletions encexp/text_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,41 +464,6 @@ def transform(self, texts):
return X / np.c_[_norm]
return X

def predict(self, texts):
"""Predict"""
X = self.transform(texts)
return self.estimator.predict(X)

def decision_function(self, texts):
"""Decision function"""
X = self.transform(texts)
hy = self.estimator.decision_function(X)
if hy.ndim == 1:
return np.c_[hy]
return hy

def train_predict_decision_function(self, D, y=None):
"""Train and predict the decision"""
if y is None:
y = np.array([x['klass'] for x in D])
if not isinstance(y, np.ndarray):
y = np.array(y)
nclass = np.unique(y).shape[0]
X = self.transform(D)
if nclass == 2:
hy = np.empty(X.shape[0])
else:
hy = np.empty((X.shape[0], nclass))
kwargs = dict(random_state=0, shuffle=True)
if self.kfold_kwargs is not None:
kwargs.update(self.kfold_kwargs)
for tr, vs in self.kfold_class(**kwargs).split(X, y):
m = clone(self).estimator.fit(X[tr], y[tr])
hy[vs] = m.decision_function(X[vs])
if hy.ndim == 1:
return np.c_[hy]
return hy

def fill(self, inplace: bool=True, names: list=None):
"""Fill weights with the missing dimensions"""
weights = self.weights
Expand Down Expand Up @@ -528,10 +493,11 @@ def build_tailored(self, data, load=False, **kwargs):
return None

get_text = self.bow.get_text
if load and isinstance(self.tailored, str) and isfile(self.tailored):
_ = self.__class__(EncExp_filename=self.tailored)
self.__iadd__(_)
self._tailored_built = True
if isinstance(self.tailored, str) and isfile(self.tailored):
if load:
_ = self.__class__(EncExp_filename=self.tailored)
self.__iadd__(_)
self._tailored_built = True
return None
iden, path = mkstemp()
with open(iden, 'w', encoding='utf-8') as fpt:
Expand Down Expand Up @@ -649,7 +615,42 @@ def estimator(self):

@estimator.setter
def estimator(self, value):
self._estimator = value
self._estimator = value

def predict(self, texts):
"""Predict"""
X = self.transform(texts)
return self.estimator.predict(X)

def decision_function(self, texts):
"""Decision function"""
X = self.transform(texts)
hy = self.estimator.decision_function(X)
if hy.ndim == 1:
return np.c_[hy]
return hy

def train_predict_decision_function(self, D, y=None):
"""Train and predict the decision"""
if y is None:
y = np.array([x['klass'] for x in D])
if not isinstance(y, np.ndarray):
y = np.array(y)
nclass = np.unique(y).shape[0]
X = self.transform(D)
if nclass == 2:
hy = np.empty(X.shape[0])
else:
hy = np.empty((X.shape[0], nclass))
kwargs = dict(random_state=0, shuffle=True)
if self.kfold_kwargs is not None:
kwargs.update(self.kfold_kwargs)
for tr, vs in self.kfold_class(**kwargs).split(X, y):
m = clone(self).estimator.fit(X[tr], y[tr])
hy[vs] = m.decision_function(X[vs])
if hy.ndim == 1:
return np.c_[hy]
return hy

def __sklearn_clone__(self):
ins = super(EncExp, self).__sklearn_clone__()
Expand Down
Loading