Implement a basic linear regression model in Python.
TechnicalAI EngineerML EngineerAI Application DevTo implement a basic linear regression model in Python, I would use the scikit-learn library. First, I would import the necessary modules and load the dataset. Then, I'd split the data into training and testing sets. After that, I would create a model instance, fit it to the training data, and finally evaluate its performance on the test set.
Here's a quick code snippet:
from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) model = LinearRegression() model.fit(X_train, y_train) y_pred = model.predict(X_test)