写xgboost回归预测模型代码
时间: 2023-10-19 17:05:45 浏览: 109
Sure, I can help you with that! Here's an example code for XGBoost regression model:
```
import pandas as pd
import numpy as np
import xgboost as xgb
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
# Load data
data = pd.read_csv('data.csv')
# Split data into train and test sets
X_train, X_test, y_train, y_test = train_test_split(data.drop('target', axis=1), data['target'], test_size=0.2, random_state=42)
# Define XGBoost model
model = xgb.XGBRegressor(objective='reg:squarederror', n_estimators=1000, learning_rate=0.05)
# Train model
model.fit(X_train, y_train)
# Make predictions on test set
y_pred = model.predict(X_test)
# Evaluate model performance
mse = mean_squared_error(y_test, y_pred)
print('MSE: ', mse)
```
Hope this helps! Let me know if you have any further questions.
阅读全文