generated from shivpalSW/dvc-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stage -02 train data tfidf matrix saved
- Loading branch information
Showing
2 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
import logging | ||
import pandas as pd | ||
import joblib | ||
import scipy.sparse as sparse | ||
import numpy as np | ||
|
||
def save_matrix(df, matrix, out_path): | ||
id_matrix = sparse.csr_matrix(df.id.astype(np.int64)).T | ||
label_matrix = sparse.csr_matrix(df.label.astype(np.int64)).T | ||
|
||
result = sparse.hstack([id_matrix, label_matrix, matrix], format="csr") | ||
|
||
msg = f"The ouput matrix {out_path} of size {result.shape} and data type: {result.dtype}" | ||
logging.info(msg) | ||
joblib.dump(result, out_path) |