❔ SciKit-Learn Nasıl Çalışır?
👶 Scikit-Learn Basit Kullanım
from sklearn.linear_model import LinearRegression
lr = LinearRegression(fit_intercept=True, normalize=False)
lr.fit(X.reshape(-1, 1), y)
lr.coef_, lr.intercept_
predictions = lr.predict(X.reshape(-1, 1))
plt.plot(X, y, '.', label='data')
plt.plot(X, predictions, label='model')
plt.legend();
👨💻 Scikit-Learn PipeLine Kullanımı
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import PolynomialFeatures
pipe = Pipeline([
('polynomial_transform', PolynomialFeatures(3)),
('linear_fit', LinearRegression())
])
pipe.fit(X.reshape(-1, 1), y)
predictions = pipe.predict(X.reshape(-1, 1))
plt.plot(X, y, '.', label='data')
plt.plot(X, predictions, label='model')
plt.legend();
X = np.linspace(0, 4, 100)
y = X**exp + np.random.randn(X.shape[0])/10
predictions = pipe.predict(X.reshape(-1, 1))
plt.plot(X, y, '.', label='data')
plt.plot(X, predictions, label='model')
plt.legend()