Друзья, полноценный пост будет завтра, сегодня попробую вам че нить написать интересное 🫡
Please open Telegram to view this post
VIEW IN TELEGRAM
CodeLab
X_new = np.linspace(-3, 3, 200).reshape(200, 1) # Создаем равномерные точки в диапазоне [-3, 3]
X_new_poly = poly.transform(X_new) # Применяем полиномиальное преобразование
y_new = model.predict(X_new_poly) # Предсказываем значения
plt.plot(X_new, y_new, "r-", linewidth=2, label="Predictions") # Линия предсказаний (красная потому что r)
plt.plot(x_train, y_train, "b.", label='Training points') # Обучающие данные (синие )
plt.plot(x_test, y_test, "g.", label='Testing points') # Тестовые данные (зеленые)
plt.xlabel("X")
plt.ylabel("y")
plt.legend()
plt.show()
Please open Telegram to view this post
VIEW IN TELEGRAM
print(model.coef_) # [[1.5 0.7]]
print(model.intercept_) # [2.0]
Что будет выводить
R**2 score: 0.8533
MAE: 0.8395
MSE: 1.0314
Коэффициенты модели: [[0.95958032 0.785119 ]]
Свободный член (intercept): [2.13459906]
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.metrics import r2_score
⚙️ Линейная: y= 3x + 2⚙️ Квадратичная: y = -2x² + 4x + 1
.... и так далее
-3x² — добавляет изгиб
x — линейная зависимоть
+5 — смещение вверх, чтобы
np.random.seed(42)
X = np.linspace(-3, 3, 100).reshape(-1, 1)
y = 2 * X ** 3 - 3 * X**2 + X + 5 + np.random.randn(100, 1) * 5
def plot_poly_regression(X, y, degree):
poly = PolynomialFeatures(degree = degree)
X_poly = poly.fit_transform(X)
model = LinearRegression()
model.fit(X_poly, y)
y_pred = model.predict(X_poly)
r2 = r2_score(y, y_pred)
plt.scatter(X, y, color = 'blue', label = 'Исходные данные')
plt.plot(X, y_pred, color = 'blue', label = f'Полином {degree} - й степени (R)²={r2:.3f})')
plt.title(f'Полиномиальная регрессия (степень {degree})')
plt.xlabel('X')
plt.ylabel('y')
plt.legend()
plt.show()
plot_poly_regression(X, y, 1)
plot_poly_regression(X, y, 2)
plot_poly_regression(X, y, 3)
plot_poly_regression(X, y, 5)
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Друзья, готовлю крупный крутецкий пост, наберитесь терпения 🙏 🙏
Please open Telegram to view this post
VIEW IN TELEGRAM
import numpy as np
def sigmoid(x):
return 1 / (1 + np.exp(-x))
def deriv_sigmoid(x):
fx = sigmoid(x)
return fx * (1 - fx)
Please open Telegram to view this post
VIEW IN TELEGRAM