<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic notebook stuck at &amp;quot;filtering data&amp;quot; or waiting to run in Machine Learning</title>
    <link>https://community.databricks.com/t5/machine-learning/notebook-stuck-at-quot-filtering-data-quot-or-waiting-to-run/m-p/107818#M3934</link>
    <description>&lt;P&gt;Hi, my data is in vector sparse representaion, and it was working fine (display and training ml models), I added few features that converted data from sparse to dense represenation and after that anything I want to perform on data stuck(display or ml model). The ram maxed out to 28 , I dont know if it is compute or data represeation (dense vs sparse) issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;its not even writing a new table in database, when i run any &amp;nbsp; block it says "filtering data" and stuck there . I run an ML model during night but it was still stuck in the morning (8 hours)&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jan 2025 13:29:39 GMT</pubDate>
    <dc:creator>harry_dfe</dc:creator>
    <dc:date>2025-01-30T13:29:39Z</dc:date>
    <item>
      <title>notebook stuck at "filtering data" or waiting to run</title>
      <link>https://community.databricks.com/t5/machine-learning/notebook-stuck-at-quot-filtering-data-quot-or-waiting-to-run/m-p/107818#M3934</link>
      <description>&lt;P&gt;Hi, my data is in vector sparse representaion, and it was working fine (display and training ml models), I added few features that converted data from sparse to dense represenation and after that anything I want to perform on data stuck(display or ml model). The ram maxed out to 28 , I dont know if it is compute or data represeation (dense vs sparse) issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;its not even writing a new table in database, when i run any &amp;nbsp; block it says "filtering data" and stuck there . I run an ML model during night but it was still stuck in the morning (8 hours)&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2025 13:29:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/notebook-stuck-at-quot-filtering-data-quot-or-waiting-to-run/m-p/107818#M3934</guid>
      <dc:creator>harry_dfe</dc:creator>
      <dc:date>2025-01-30T13:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: notebook stuck at "filtering data" or waiting to run</title>
      <link>https://community.databricks.com/t5/machine-learning/notebook-stuck-at-quot-filtering-data-quot-or-waiting-to-run/m-p/136393#M4377</link>
      <description>&lt;P&gt;Greetings&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/146916"&gt;@harry_dfe&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="paragraph"&gt;Thanks for the details — this almost certainly stems from your data flipping from a &lt;STRONG&gt;sparse&lt;/STRONG&gt; vector representation to a &lt;STRONG&gt;dense&lt;/STRONG&gt; one, which explodes per‑row memory and stalls actions like display, writes, and ML training.&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;H3&gt;Why this is happening&lt;/H3&gt;
&lt;UL&gt;
&lt;LI class="paragraph"&gt;A &lt;STRONG&gt;dense vector&lt;/STRONG&gt; of size n stores all n values (8 bytes each for doubles), so its storage grows linearly with n. A &lt;STRONG&gt;sparse vector&lt;/STRONG&gt; stores only non‑zeros plus indices, and is much smaller when most entries are zero. In Spark MLlib, dense costs ≈ 8·n bytes, while sparse costs ≈ 12·nnz + 4 bytes; sparse is better whenever more than ~1/3 of entries are zero.&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class="paragraph"&gt;Some &lt;STRONG&gt;transformers force dense output&lt;/STRONG&gt;:
&lt;UL&gt;
&lt;LI&gt;StandardScaler withMean=true creates a dense output by design; it’s only safe with sparse if withMean=false.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/DIV&gt;
&lt;UL&gt;
&lt;LI&gt;MinMaxScaler turns zeros into non‑zeros during rescaling, so it outputs DenseVector even for sparse input.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class="paragraph"&gt;Many &lt;STRONG&gt;MLlib algorithms leverage sparsity&lt;/STRONG&gt; for speed and memory (e.g., logistic regression, SVM, Lasso, Naive Bayes, KMeans), so losing sparsity can dramatically slow training and increase memory pressure.&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;H3 class="paragraph"&gt;Quick triage you can run now&lt;/H3&gt;
&lt;DIV class="paragraph"&gt;1. Measure vector size and density on a small sample. If density jumped, that confirms the cause. ```python from pyspark.sql.types import StructType, StructField, IntegerType, DoubleType from pyspark.sql.functions import udf, col from pyspark.ml.linalg import VectorUDT&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;schema = StructType([ StructField("size", IntegerType(), False), StructField("nnz", IntegerType(), False), StructField("density", DoubleType(), False) ])&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;def vstats(v): nnz = v.numNonzeros() return (v.size, nnz, float(nnz) / float(v.size) if v.size else 0.0)&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;vstats_udf = udf(vstats, schema)&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;sample = df.sample(0.001, seed=42) # adjust fraction as needed density_df = sample.select(vstats_udf("features").alias("s")) \ .select("s.size", "s.nnz", "s.density") density_df.summary("count", "mean", "min", "max").show() ```&lt;/DIV&gt;
&lt;OL start="2"&gt;
&lt;LI&gt;
&lt;DIV class="paragraph"&gt;Avoid displaying huge vectors. Use display/select on non‑vector columns, or drop the features column for inspection: &lt;CODE&gt;python
display(df.select("id", "label").limit(1000))
# Or, if you must preview feature values, only show a small slice:
from pyspark.sql.functions import expr
display(df.select(expr("slice(features, 1, 20) as features_slice")).limit(100))
&lt;/CODE&gt;&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class="paragraph"&gt;Remove pipeline stages that force dense:
&lt;UL&gt;
&lt;LI&gt;If you use StandardScaler, set withMean=False to preserve sparsity: &lt;CODE&gt;python
from pyspark.ml.feature import StandardScaler
scaler = StandardScaler(withMean=False, withStd=True, inputCol="features", outputCol="scaledFeatures")
model = scaler.fit(df)
df_scaled = model.transform(df)
&lt;/CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;/DIV&gt;
&lt;UL&gt;
&lt;LI&gt;Avoid MinMaxScaler on high‑dimensional sparse features; it will output dense vectors:&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class="paragraph"&gt;If a recent step converted to dense, revert or rework the step:
&lt;UL&gt;
&lt;LI&gt;Prefer sparse‑friendly feature engineering (e.g., HashingTF, CountVectorizer, OneHotEncoder) and avoid transformations that create many small non‑zeros.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class="paragraph"&gt;For writes that show “filtering data” and stall, write without the heavy vector column: &lt;CODE&gt;python
(df.drop("features")
.repartition(200)                 # adjust based on data size
.write.mode("overwrite")
.saveAsTable("schema.table_name"))
&lt;/CODE&gt;&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;H3 class="paragraph"&gt;ML pipeline guidance&lt;/H3&gt;
&lt;UL&gt;
&lt;LI class="paragraph"&gt;Keep features in &lt;STRONG&gt;SparseVector&lt;/STRONG&gt; wherever possible; many MLlib algorithms compute faster and use less memory with sparse input.&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class="paragraph"&gt;If you truly need dense for a downstream stage, lower dimensionality first (e.g., PCA or feature selection) so the dense vector is small. Note that some reducers still output dense, so apply them after you’ve minimized feature count.&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV class="paragraph"&gt;Be careful with scalers:
&lt;UL&gt;
&lt;LI&gt;StandardScaler: use withMean=false to keep sparse; withMean=true centers data and forces dense output.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/DIV&gt;
&lt;UL&gt;
&lt;LI&gt;MinMaxScaler: always outputs DenseVector; avoid on wide sparse vectors.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;H3 class="paragraph"&gt;If you still need to convert back to sparse&lt;/H3&gt;
&lt;DIV class="paragraph"&gt;Only as a last resort (and only on reasonably sized vectors), you can convert DenseVector to SparseVector, but it requires scanning the array — do this on a small subset or after dimensionality reduction: ```python from pyspark.ml.linalg import Vectors, VectorUDT, DenseVector from pyspark.sql.functions import udf&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;def to_sparse(v): if isinstance(v, DenseVector): arr = v.toArray() idx_vals = [(i, float(val)) for i, val in enumerate(arr) if val != 0.0] return Vectors.sparse(v.size, idx_vals) return v # already sparse&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;to_sparse_udf = udf(to_sparse, VectorUDT()) df_sparse = df.withColumn("features", to_sparse_udf("features")) ```&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;H3 class="paragraph"&gt;What likely caused the “RAM maxed to 28” symptom&lt;/H3&gt;
&lt;DIV class="paragraph"&gt;Converting high‑dimensional sparse features to dense increases each row’s in‑memory footprint by orders of magnitude. Actions like display (which collect a sample to the driver), wide shuffles during writes, and ML training that materializes feature vectors will then hit driver/executor memory ceilings and appear “stuck.” Switching back to sparse or reducing dimensionality typically resolves this.&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="paragraph"&gt;Hope this helps, Louis.&lt;/DIV&gt;</description>
      <pubDate>Tue, 28 Oct 2025 12:27:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/notebook-stuck-at-quot-filtering-data-quot-or-waiting-to-run/m-p/136393#M4377</guid>
      <dc:creator>Louis_Frolio</dc:creator>
      <dc:date>2025-10-28T12:27:02Z</dc:date>
    </item>
  </channel>
</rss>

