Skip to content

Commit aa19051

Browse files
committed
[MINOR][MLLIB] Declare size on PySpark Vector
1 parent 215a146 commit aa19051

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎python/pyspark/mllib/classification.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ def __init__(
202202
self._dataWithBiasSize = None
203203
self._weightsMatrix = None
204204
else:
205-
self._dataWithBiasSize = self._coeff.size // ( # type: ignore[attr-defined]
206-
self._numClasses - 1
207-
)
205+
self._dataWithBiasSize = self._coeff.size // (self._numClasses - 1)
208206
self._weightsMatrix = self._coeff.toArray().reshape(
209207
self._numClasses - 1, self._dataWithBiasSize
210208
)
@@ -261,11 +259,11 @@ def predict(
261259

262260
best_class = 0
263261
max_margin = 0.0
264-
if x.size + 1 == self._dataWithBiasSize: # type: ignore[attr-defined]
262+
if x.size + 1 == self._dataWithBiasSize:
265263
for i in range(0, self._numClasses - 1):
266264
margin = (
267265
x.dot(self._weightsMatrix[i][0 : x.size]) # type: ignore[attr-defined]
268-
+ self._weightsMatrix[i][x.size] # type: ignore[attr-defined]
266+
+ self._weightsMatrix[i][x.size]
269267
)
270268
if margin > max_margin:
271269
max_margin = margin
@@ -936,7 +934,7 @@ def setInitialWeights(
936934
self._model = LogisticRegressionModel(
937935
initialWeights,
938936
0,
939-
initialWeights.size, # type: ignore[attr-defined]
937+
initialWeights.size,
940938
2,
941939
)
942940
return self

‎python/pyspark/mllib/linalg/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ class Vector:
306306
Abstract class for DenseVector and SparseVector
307307
"""
308308

309+
size: int
310+
309311
def toArray(self) -> np.ndarray:
310312
"""
311313
Convert the vector into an numpy.ndarray

0 commit comments

Comments
 (0)