-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinear_model.py
More file actions
31 lines (21 loc) · 1005 Bytes
/
Copy pathlinear_model.py
File metadata and controls
31 lines (21 loc) · 1005 Bytes
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
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import pandas as pd
import numpy as np
from sklearn.metrics import mean_absolute_error, mean_squared_error
from metrics import main
with open("validate_answers.tsv") as f:
answr = pd.read_csv(f, sep="\t")
x = pd.DataFrame(answr["at_least_two"])
y = pd.DataFrame(answr["at_least_three"])
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
model = LinearRegression()
model.fit(x_train, y_train)
y_pred = model.predict(x_test)
# Оцениваем качество модели
mse = np.mean((y_test - y_pred)**2)
r2 = model.score(x_test, y_test)
print("Средняя квадратичная ошибка (MSE):", mse)
print("Коэффициент детерминации (R^2):", r2)
print("Коэффициент x:", model.coef_[0]) # Наклон
print("Смещение b:", model.intercept_) # Смещение