Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ahendriksen committed Nov 15, 2022
1 parent 677a08b commit 88402bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 9 additions & 4 deletions python/cuml/linear_model/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ class LinearPredictMixin:
Predicts `y` values for `X`.

"""
coef_cp, n_feat, n_targets, _ = input_to_cupy_array(self.coef_)
if 1 < n_targets:
if self.coef_ is None:
raise ValueError(
"LinearModel.predict() cannot be called before fit(). "
"Please fit the model first."
)
if len(self.coef_.shape) == 2 and self.coef_.shape[1] > 1:
# Handle multi-target prediction in Python.
coef_cp = input_to_cupy_array(self.coef_).array
X_cp = input_to_cupy_array(
X,
check_dtype=self.dtype,
Expand All @@ -79,8 +84,8 @@ class LinearPredictMixin:
).array
intercept_cp = input_to_cupy_array(self.intercept_).array
preds_cp = X_cp @ coef_cp + intercept_cp
preds = input_to_cuml_array(preds_cp).array
return preds
# preds = input_to_cuml_array(preds_cp).array # TODO:remove
return preds_cp

# Handle single-target prediction in C++
X_m, n_rows, n_cols, dtype = \
Expand Down
8 changes: 3 additions & 5 deletions python/cuml/linear_model/linear_regression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,10 @@ class LinearRegression(Base,
self.algo = 0

if 1 < y_cols:
del X_m
del y_m
if sample_weight is not None:
del sample_weight_m
if sample_weight is None:
sample_weight_m = None

return self._fit_multi_target(X, y, convert_dtype, sample_weight)
return self._fit_multi_target(X_m, y_m, convert_dtype, sample_weight_m)

self.coef_ = CumlArray.zeros(self.n_cols, dtype=self.dtype)
cdef uintptr_t coef_ptr = self.coef_.ptr
Expand Down

0 comments on commit 88402bf

Please sign in to comment.