You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Simple Example - Linear regression with a linear feature setfromsklearn.model_selectionimporttrain_test_splitfromsklearn.linear_modelimportLinearRegressionX, y=generate_data(n_points=100, eps=2)
X_train, X_val, y_train, y_val=train_test_split(X, y, test_size=0.1)
model=LinearRegression()
model.fit(X_train, y_train)
prediction=model.predict(X)
score=model.score(X_test, y_test)
class:
quite-wide-step
scikit-learn: small demo
# Let's do the same with polynomial fitfromsklearn.preprocessingimportPolynomialFeaturespf=PolynomialFeatures(degree=3)
pf.fit(X_train)
X_train_poly=pf.transform(X_train)
model=LinearRegression()
model.fit(X_train_poly, y_train)
class:
quite-wide-step
scikit-learn: small demo
# Or easier, combine them in a pipeline!fromsklearn.pipelineimportmake_pipelinepipeline=make_pipeline(
PolynomialFeatures(degree=3),
LinearRegression()
)
pipeline.fit(X_train, y_train)
pipeline.score(X_test, y_test)