You can download this code by clicking the button below.
This code is now available for download.
This function trains a CatBoost regression model on the Boston Housing dataset and returns the predictions on the test set.
Technology Stack : CatBoost, scikit-learn
Code Type : Function
Code Difficulty : Intermediate
def random_predict(input_features):
import catboost as cb
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
# Load Boston Housing dataset
boston = load_boston()
X = boston.data
y = boston.target
# Split the dataset into train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Create a CatBoost model
model = cb.CatBoostRegressor()
# Train the model
model.fit(X_train, y_train)
# Make predictions on the test set
predictions = model.predict(X_test)
return predictions