Support Pandas linear regression
This commit is contained in:
@@ -14,11 +14,11 @@ class MVStrategy(ABC):
|
|||||||
return df
|
return df
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def list_available(series: Series) -> list['MVStrategy']:
|
def list_available(df: DataFrame, series: Series) -> list['MVStrategy']:
|
||||||
"""Get all the strategies that can be used."""
|
"""Get all the strategies that can be used."""
|
||||||
choices = [DropStrategy(), ModeStrategy()]
|
choices = [DropStrategy(), ModeStrategy()]
|
||||||
if is_numeric_dtype(series):
|
if is_numeric_dtype(series):
|
||||||
choices.extend((MeanStrategy(), MedianStrategy()))
|
choices.extend((MeanStrategy(), MedianStrategy(), LinearRegressionStrategy()))
|
||||||
return choices
|
return choices
|
||||||
|
|
||||||
|
|
||||||
@@ -68,3 +68,12 @@ class ModeStrategy(PositionStrategy):
|
|||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return "Use mode"
|
return "Use mode"
|
||||||
|
|
||||||
|
|
||||||
|
class LinearRegressionStrategy(MVStrategy):
|
||||||
|
def apply(self, df: DataFrame, label: str, series: Series) -> DataFrame:
|
||||||
|
series.interpolate(inplace=True)
|
||||||
|
return df
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return "Use linear regression"
|
||||||
|
@@ -7,7 +7,7 @@ if "data" in st.session_state:
|
|||||||
|
|
||||||
for column, series in data.items():
|
for column, series in data.items():
|
||||||
missing_count = series.isna().sum()
|
missing_count = series.isna().sum()
|
||||||
choices = MVStrategy.list_available(series)
|
choices = MVStrategy.list_available(data, series)
|
||||||
option = st.selectbox(
|
option = st.selectbox(
|
||||||
f"Missing values of {column} ({missing_count})",
|
f"Missing values of {column} ({missing_count})",
|
||||||
choices,
|
choices,
|
||||||
|
Reference in New Issue
Block a user