mirror of
https://github.com/shizand/statapp.git
synced 2025-04-01 23:23:45 +03:00
сделал рефакторинг и исправил отображение
This commit is contained in:
parent
c410df2c5d
commit
ba85356ef9
@ -21,7 +21,7 @@ from dataclasses import dataclass
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from statapp._vendor.multipolyfit import multipolyfit
|
||||
from statapp._vendor.multipolyfit import multipolyfit, getTerms
|
||||
|
||||
DIRECT_LINK = 0
|
||||
INDIRECT_LINK = 1
|
||||
@ -59,15 +59,18 @@ def varianceAnalysis(data):
|
||||
def correlationAnalysis(data):
|
||||
return pd.DataFrame(data).corr().to_numpy()
|
||||
|
||||
|
||||
@dataclass()
|
||||
class RegressionResult:
|
||||
"""
|
||||
Attributes:
|
||||
paramsAndImportance (np.ndarray): Параметры модели
|
||||
paramsAndImportance (np.ndarray): Параметры модели. Первая колонка -
|
||||
residualVariance (np.float64): Остаточная дисперсия
|
||||
monomials (list): Список одночленов в строковом виде без коэффициентов. Свободный член - c
|
||||
"""
|
||||
paramsAndImportance: np.ndarray
|
||||
residualVariance: np.float64
|
||||
monomials: list
|
||||
|
||||
|
||||
def linearPolynom(inputData) -> RegressionResult:
|
||||
@ -94,20 +97,10 @@ def linearPolynom(inputData) -> RegressionResult:
|
||||
|
||||
return RegressionResult(
|
||||
out.to_numpy(),
|
||||
np.float64(mse[0])
|
||||
np.float64(mse[0]),
|
||||
['c'] + [f'x{i}' for i in range(1, len(params))]
|
||||
)
|
||||
|
||||
@dataclass()
|
||||
class ExtendedRegressionResult:
|
||||
"""
|
||||
Attributes:
|
||||
paramsAndImportance (np.ndarray): Параметры модели
|
||||
residualVariance (np.float64): Остаточная дисперсия
|
||||
"""
|
||||
paramsAndImportance: np.ndarray
|
||||
residualVariance: np.float64
|
||||
powers: list
|
||||
|
||||
|
||||
def squaredPolynom(inputData):
|
||||
x = inputData[:, 1:]
|
||||
@ -119,8 +112,8 @@ def squaredPolynom(inputData):
|
||||
out[0] = betas
|
||||
out[1] = tStatistics
|
||||
|
||||
return ExtendedRegressionResult(
|
||||
return RegressionResult(
|
||||
out.to_numpy(),
|
||||
np.float64(mse[0]),
|
||||
powers
|
||||
['c' if str(x) == '1' else str(x) for x in getTerms(powers)]
|
||||
)
|
||||
|
@ -21,7 +21,7 @@ from PySide2.QtWidgets import QDialog, QHeaderView
|
||||
|
||||
from statapp.calculations import linearPolynom
|
||||
from statapp.mathtex_header_view import MathTexHeaderView
|
||||
from statapp.models.linear_polynom_model import LinearPolynomModel
|
||||
from statapp.models.regression_result_model import RegressionResultModel
|
||||
from statapp.ui.ui_linear_polynom_window import Ui_LinearPolynomWindow
|
||||
from statapp.utils import addIcon
|
||||
|
||||
@ -35,11 +35,9 @@ class LinearPolynomWindow(QDialog):
|
||||
|
||||
result = linearPolynom(data)
|
||||
|
||||
self.model = LinearPolynomModel(result.paramsAndImportance.round(2))
|
||||
self.model = RegressionResultModel(result)
|
||||
self.ui.tableView.setModel(self.model)
|
||||
self.ui.tableView.setVerticalHeader(
|
||||
MathTexHeaderView(self.ui.tableView)
|
||||
)
|
||||
self.ui.tableView.setVerticalHeader(MathTexHeaderView(self.ui.tableView))
|
||||
header = self.ui.tableView.horizontalHeader()
|
||||
header.setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
|
||||
|
||||
|
@ -70,11 +70,11 @@ class MainWindow(QMainWindow):
|
||||
self.updateActionsEnabled()
|
||||
#
|
||||
# Для быстрой отладки
|
||||
# n = 10
|
||||
# y = generateYValues(100, 5, n)
|
||||
# x1 = generateXValues(20, 2, 0, y)
|
||||
# x2 = generateXValues(10, 1, 0, y)
|
||||
# self.model.updateAllData(np.concatenate([y, x1, x2], axis=1))
|
||||
n = 10
|
||||
y = generateYValues(100, 5, n)
|
||||
x1 = generateXValues(20, 2, 0, y)
|
||||
x2 = generateXValues(10, 1, 0, y)
|
||||
self.model.updateAllData(np.concatenate([y, x1, x2], axis=1))
|
||||
|
||||
|
||||
def updateActionsEnabled(self):
|
||||
|
@ -72,6 +72,12 @@ class CacheQPixMap(dict):
|
||||
class MathTexHeaderView(QHeaderView):
|
||||
def __init__(self, view, orientation=QtCore.Qt.Vertical):
|
||||
super().__init__(orientation, view)
|
||||
|
||||
if orientation == QtCore.Qt.Vertical:
|
||||
self.setStyleSheet(
|
||||
"QHeaderView::section { padding-left: 15px; padding-right: 15px }"
|
||||
)
|
||||
|
||||
self.converter = CacheQPixMap()
|
||||
|
||||
def paintSection(self, painter, rect, logicalIndex):
|
||||
|
@ -17,15 +17,18 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from PySide2.QtCore import QModelIndex
|
||||
|
||||
from statapp.calculations import RegressionResult
|
||||
from statapp.models.ro_table_model import ROTableModel
|
||||
|
||||
|
||||
class LinearPolynomModel(ROTableModel):
|
||||
class RegressionResultModel(ROTableModel):
|
||||
def __init__(self, result: RegressionResult):
|
||||
data = result.paramsAndImportance
|
||||
super().__init__(data)
|
||||
self._monomials = result.monomials
|
||||
|
||||
def getHorizontalHeader(self):
|
||||
return ['Коэффициент регрессии', 'Коэффициент значимости']
|
||||
|
||||
def getVerticalHeader(self):
|
||||
count = (self.rowCount(QModelIndex()))
|
||||
return ['c'] + [f'x{i}' for i in range(1, count)]
|
||||
return self._monomials
|
@ -1,29 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2023 Maxim Slipenko, Eugene Lazurenko.
|
||||
#
|
||||
# This file is part of Statapp
|
||||
# (see https://github.com/shizand/statapp).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from statapp._vendor.multipolyfit import getTerms
|
||||
from statapp.models.linear_polynom_model import LinearPolynomModel
|
||||
|
||||
|
||||
class SquaredPolynomModel(LinearPolynomModel):
|
||||
powers: list
|
||||
|
||||
def getVerticalHeader(self):
|
||||
return ['c' if str(x) == '1' else str(x) for x in getTerms(self.powers)]
|
@ -21,10 +21,11 @@ from PySide2.QtWidgets import QDialog, QHeaderView
|
||||
|
||||
from statapp.calculations import squaredPolynom
|
||||
from statapp.mathtex_header_view import MathTexHeaderView
|
||||
from statapp.models.squared_polynom_model import SquaredPolynomModel
|
||||
from statapp.models.regression_result_model import RegressionResultModel
|
||||
from statapp.ui.ui_squared_polynom_window import Ui_SquaredPolynomWindow
|
||||
from statapp.utils import addIcon
|
||||
|
||||
|
||||
class SquaredPolynomWindow(QDialog):
|
||||
def __init__(self, data):
|
||||
super().__init__()
|
||||
@ -34,15 +35,9 @@ class SquaredPolynomWindow(QDialog):
|
||||
|
||||
result = squaredPolynom(data)
|
||||
|
||||
# Не округляем, т.к. может получиться коэффициент = 0 и значимый (t-критерий)
|
||||
self.model = SquaredPolynomModel(result.paramsAndImportance)
|
||||
self.model.powers = result.powers
|
||||
# self.ui.tableView.setItemDelegate(TermItemDelegate())
|
||||
self.model = RegressionResultModel(result)
|
||||
self.ui.tableView.setModel(self.model)
|
||||
self.ui.tableView.setVerticalHeader(MathTexHeaderView(self.ui.tableView))
|
||||
|
||||
# x = h.indexWidget(h.model().index(0, 0))
|
||||
|
||||
header = self.ui.tableView.horizontalHeader()
|
||||
header.setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
|
||||
|
||||
|
@ -17,7 +17,17 @@
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTableView" name="tableView"/>
|
||||
<widget class="QTableView" name="tableView">
|
||||
<attribute name="horizontalHeaderMinimumSectionSize">
|
||||
<number>40</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderMinimumSectionSize">
|
||||
<number>40</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>40</number>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
|
3
statapp/ui/ui_linear_polynom_window.py
generated
3
statapp/ui/ui_linear_polynom_window.py
generated
@ -44,6 +44,9 @@ class Ui_LinearPolynomWindow(object):
|
||||
self.gridLayout.setObjectName(u"gridLayout")
|
||||
self.tableView = QTableView(LinearPolynomWindow)
|
||||
self.tableView.setObjectName(u"tableView")
|
||||
self.tableView.horizontalHeader().setMinimumSectionSize(40)
|
||||
self.tableView.verticalHeader().setMinimumSectionSize(40)
|
||||
self.tableView.verticalHeader().setDefaultSectionSize(40)
|
||||
|
||||
self.gridLayout.addWidget(self.tableView, 0, 0, 1, 1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user