Saltar navegación

2.3.2 Polynomial Regression

Información

Polynomial Regression extends Linear Regression by allowing for a polynomial relationship between the independent and dependent variables. It is useful for modeling non-linear relationships.

Vídeo

[soon]

Polynomial Regression

[soon]

Practice

Let's build a Polynomial Regression model to predict house prices based on square footage.

from sklearn.preprocessing import PolynomialFeatures

# Create polynomial features
poly = PolynomialFeatures(degree=2)
X_poly = poly.fit_transform(X)

# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X_poly, y, test_size=0.2, random_state=42)

# Create a Linear Regression model
model = LinearRegression()

# Train the model
model.fit(X_train, y_train)

# Make predictions
predictions = model.predict(X_test)

# Evaluate the model
mae = mean_absolute_error(y_test, predictions)
mse = mean_squared_error(y_test, predictions)
r2 = r2_score(y_test, predictions)
print(f'MAE: {mae}, MSE: {mse}, R2: {r2}')

Feito con eXeLearning (Nova xanela)