Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
attr_inds,
name_items,
points,
max_width,
point_text,
name_offset,
)
probs_item, nomogram_foot = self.create_footer_nomogram(
probs_text, d, minimums, max_width, name_offset
)
for item in self.feature_items.values():
item.dot.point_dot = point_item.dot
item.dot.probs_dot = probs_item.dot
item.dot.vertical_line = self.hidden_vertical_line
self.nomogram = nomogram = NomogramItem()
nomogram.add_items([nomogram_head, self.nomogram_main, nomogram_foot])
self.scene.addItem(nomogram)
self.set_feature_marker_values()
rect = QRectF(
self.scene.itemsBoundingRect().x(),
self.scene.itemsBoundingRect().y(),
self.scene.itemsBoundingRect().width(),
self.nomogram.preferredSize().height(),
).adjusted(10, 0, 20, 0)
self.scene.setSceneRect(rect)
# Clip top and bottom (60 and 150) parts from the main view
self.view.setSceneRect(
rect.x(), rect.y() + 80, rect.width() - 10, rect.height() - 160
cls_index = self.target_class_index
min_p = min(p.min() for p in points)
max_p = max(p.max() for p in points)
values = self.get_ruler_values(min_p, max_p, max_width)
min_p, max_p = min(values), max(values)
diff_ = np.nan_to_num(max_p - min_p)
scale_x = max_width / diff_ if diff_ else max_width
nomogram_header = NomogramItem()
point_item = RulerItem(
point_text, values, scale_x, name_offset, -scale_x * min_p
)
point_item.setPreferredSize(point_item.preferredWidth(), 35)
nomogram_header.add_items([point_item])
self.nomogram_main = NomogramItem()
cont_feature_item_class = (
ContinuousFeature2DItem
if self.cont_feature_dim_index
else ContinuousFeatureItem
)
feature_items = [
DiscreteFeatureItem(
name_item, attr.values, point, scale_x, name_offset, -scale_x * min_p
)
if attr.is_discrete
else cont_feature_item_class(
name_item,
self.log_reg_cont_data_extremes[i][cls_index],
self.get_ruler_values(
point.min(), point.max(), scale_x * point.ptp(), False
if self.align == OWNomogram.ALIGN_LEFT:
max_sum = max_sum - sum(minimums)
min_sum = min_sum - sum(minimums)
for i in range(len(k)):
k[i] = k[i] - sum([min(q) for q in [p[i] for p in self.points]])
if self.scale == OWNomogram.POINT_SCALE:
min_sum *= d
max_sum *= d
d_ = d
values = self.get_ruler_values(min_sum, max_sum, max_width)
min_sum, max_sum = min(values), max(values)
diff_ = np.nan_to_num(max_sum - min_sum)
scale_x = max_width / diff_ if diff_ else max_width
cls_var, cls_index = self.domain.class_var, self.target_class_index
nomogram_footer = NomogramItem()
def get_normalized_probabilities(val):
if not self.normalize_probabilities:
return 1 / (1 + np.exp(k[cls_index] - val / d_))
totals = self.__get_totals_for_class_values(minimums)
p_sum = np.sum(1 / (1 + np.exp(k - totals / d_)))
return 1 / (1 + np.exp(k[cls_index] - val / d_)) / p_sum
def get_points(prob):
if not self.normalize_probabilities:
return (k[cls_index] - np.log(1 / prob - 1)) * d_
totals = self.__get_totals_for_class_values(minimums)
p_sum = np.sum(1 / (1 + np.exp(k - totals / d_)))
return (k[cls_index] - np.log(1 / (prob * p_sum) - 1)) * d_
probs_item = ProbabilitiesRulerItem(
attr_inds,
name_items,
points,
max_width,
point_text,
name_offset,
):
cls_index = self.target_class_index
min_p = min(p.min() for p in points)
max_p = max(p.max() for p in points)
values = self.get_ruler_values(min_p, max_p, max_width)
min_p, max_p = min(values), max(values)
diff_ = np.nan_to_num(max_p - min_p)
scale_x = max_width / diff_ if diff_ else max_width
nomogram_header = NomogramItem()
point_item = RulerItem(
point_text, values, scale_x, name_offset, -scale_x * min_p
)
point_item.setPreferredSize(point_item.preferredWidth(), 35)
nomogram_header.add_items([point_item])
self.nomogram_main = NomogramItem()
cont_feature_item_class = (
ContinuousFeature2DItem
if self.cont_feature_dim_index
else ContinuousFeatureItem
)
feature_items = [
DiscreteFeatureItem(
name_item, attr.values, point, scale_x, name_offset, -scale_x * min_p