Для каждого из моих входных столбцов (которая представляет страну, я хочу Чтобы соответствовать модели линейной регрессии.
Все работает нормально. > . . < /p>
Вот мой код: < /p>
Код: Выделить всё
@asset(deps=[])
def train_linear_regression(duckdb: DuckDBResource):
"""Use pivot table with time serie data to forecast.
Used Linear Regression.
"""
# Setting up query.
query = "SELECT * FROM pivot_table_model"
# Execute the query.
with duckdb.get_connection() as conn:
df = conn.execute(query).df()
output = {}
for country_name in df.drop(columns=["year"]).columns:
# Setting Y.
Y = df.loc[:, country_name] # Retrieving population - pd.Series.
# Preparing linear model.
linear_regression = LinearRegression()
# Fitting the model.
linear_regression.fit(X, Y)
# Scoring.
score = linear_regression.score(X, Y)
output[country_name] = {
"model": linear_regression,
"score": float(score),
"plot": generate_plot(df),
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... l-in-asset
Мобильная версия