Python offers numerous libraries and frameworks for implementing machine learning algorithms. One popular library is scikit-learn, which provides a wide range of tools for machine learning tasks. Here's an example code snippet to train a simple linear regression model using scikit-learn:
from sklearn.linear_model import LinearRegression
# Sample input features
X = [[1], [2], [3], [4], [5]]
# Corresponding target values
y = [2, 4, 6, 8, 10]
# Create a linear regression model
model = LinearRegression()
# Train the model
model.fit(X, y)
# Make predictions
new_data = [[6], [7]]
predictions = model.predict(new_data)
print(predictions)
In this example, the model is trained on a set of input features (X) and corresponding target values (y). Once trained, the model can be used to predict the target values for new input data (new_data).