A python package that implements unweighted and weighted k-means.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

56 lines
1.2 KiB

class Point:
def __init__(self, x: int, y: int, weight: float = 1.0):
self._x = x
self._y = y
self._cluster = None
self._weight = weight
@property
def cluster(self):
return self._cluster
@cluster.setter
def cluster(self, cluster):
self._cluster = cluster
@property
def x(self):
return self._x
@property
def y(self):
return self._y
@property
def weight(self):
return self._weight
@x.setter
def x(self, x):
self._x = x
@y.setter
def y(self):
self._y = y
@weight.setter
def weight(self, weight):
if not isinstance(weight, float):
raise ValueError('Weight must be a float')
self._weight = weight
def array(self):
"""
Returns array representation for use in convex hull.
"""
return [self._x, self._y]
def __eq__(self, other):
if not isinstance(other, Point):
raise NotImplementedError('equality between points is only ' +
'defined for points ' +
f'(other={type(other)})')
return self._x == other._x and self._y == other._y