-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_preparation.py
31 lines (23 loc) · 1.24 KB
/
data_preparation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pandas as pd
import numpy as np
from typing import Tuple
class DataPreparation:
"""
Класс для подготовки данных для модели линейной регрессии.
Отвечает за загрузку данных и их преобразование в нужный формат.
"""
def __init__(self, data: dict):
self.data = data
self.df = pd.DataFrame(self.data)
def get_features_and_target(self, feature_col: str, target_col: str) -> Tuple[np.ndarray, np.ndarray]:
"""
Извлекает признаки и целевую переменную из DataFrame.
Args:
feature_col (str): название столбца с признаком.
target_col (str): название столбца с целевой переменной.
Returns:
Tuple[np.ndarray, np.ndarray]: Кортеж из признаков и целевой переменной в виде массивов numpy.
"""
X = self.df[feature_col].values.reshape(-1, 1) # Независимая переменная
y = self.df[target_col].values # Зависимая переменная
return X, y